For example:
void foo()
{
if constexpr (...)
int x = 5;
else
double x = 10.0;
bar(x);
}
This is a common case in D lang, but I did not find any information about C ++ 17.
Of course, you can use something like
std::conditional<..., int, double>::type x;
but only in elementary cases. Even different initializers (as indicated above) pose a big problem.
source
share