The statement Initialization Output mentions if constexpr and states that " if constexpr work the same way as with the extended if from this sentence."
The specification of the if with an initializer in N4606 [stmt.if] p3 explicitly allows you to use if constexpr .
This is what N4606 [stmt.if] p3 says:
Form if statement
if constexpr[opt] ( init-statement condition ) statement
equivalently
{ init-statement if constexpr[opt] ( condition ) statement }
and form if statement
if constexpr[opt] ( init-statement condition ) statement else statement
equivalently
{ init-statement if constexpr[opt] ( condition ) statement else statement }
except that the names declared in the init-statement are in the same declarative scope as those declared in the condition.
source share