Home > Enterprise >  Stuctured binding to define constants
Stuctured binding to define constants

Time:12-27

Can structured binding be used to define a bunch of constants that would be usable in a constant expression (like a case in a switch) ? How ?

To the effect of : const auto [ file_type, folder_tye, sym_type ] = 42u, 43u, 44u ;

CodePudding user response:

It is currently not possible to make a structured binding usable in constant expressions due to some technicalities of how they are specified in the standard.

That seems to be intended to be corrected via P2686, which however is currently still open and tagged C 26 and so won't be in C 23.

With the change in the paper simply adding constexpr will be enough.

  •  Tags:  
  • c
  • Related