Is "else if constexpr" after a non constexpr if, legal?

  c++, constexpr

Writing the else clause to an if constexpr condition is straightforward:

if constexpr (my_condition)
{
}
else // No special  syntax, this branch is constexpr
{
}

In the situation where my initial if is not a constexpr condition, I’ve been seeing code like this:

if (some_condition)
{
}
else 
{
  if constexpr (my_condition)
  {
  }
}

Though it may look strange, I think the following code is equivalent:

if (some_condition)
{
}
else if constexpr (my_condition)
{
}

since C++ doesn’t really have an elif clause but merely an else chained to another if. Is it correct to write else if constexpr after a non constexpr if?

Source: Windows Questions C++

LEAVE A COMMENT