selection-statement: if constexpr ( init-statement condition ) statement if constexpr ( init-statement condition ) statement else statement switch ( init-statement condition ) statement
template<typename T, typename ... Rest> void g(T&& p, Rest&& ...rs) { // ... handle p if constexpr (sizeof...(rs) > 0) g(rs...); // never instantiated with an empty argument list } extern int x; // no definition of x required int f() { if constexpr (true) return 0; else if (x) return x; else return -x; }— end example
if constexpr ( init-statement condition ) statementis equivalent to
{ init-statement if constexpr ( condition ) statement }and an if statement of the form
if constexpr ( init-statement condition ) statement else statementis equivalent to
{ init-statement if constexpr ( condition ) statement else statement }except that names declared in the init-statement are in the same declarative region as those declared in the condition.
case constant-expression :where the constant-expression shall be a converted constant expression of the adjusted type of the switch condition.
switch ( init-statement condition ) statementis equivalent to
{ init-statement switch ( condition ) statement }except that names declared in the init-statement are in the same declarative region as those declared in the condition.