How does one use concepts in if constexpr?Given the example below, what would one give to if constexpr to return 1 in case T meets the requirements of integral and else 0?
GCC9 already implements std::is_constant_evaluated. I played a little bit with it, and I realized it is somewhat tricky. Here’s my test:
I am trying to use if constexpr in the following way:Example use case:But this fails to compileBut I found the error goes away once I add else:
In C++17, if constexpr was introduced; however, there doesn't seem to be a switch constexpr (see here). Why is that? That is, if a compiler supports if constexpr, is it not also trivial for it to support switch constexpr (at worst as an if-then-else-if-etc. chain, or multiple if's with some...
Inspired by this answer, I tried to copy and paste (and add testing in main()) this code:This is very straightforward - if T is deduced as int, we want to return a tuple of [a, 0.0]. If T is deduced as double, we want to return a tuple of [0,...
It appears to me that a constexpr-if statement that is inside the discarded branch of another constexpr-if statement is evaluated in MSVC (version 15.7.3).
The following code compiles successfully with g++ 7.3.0 and fails to compile with clang++ 6.0.0 (compilation flags are -std=c++17 -Wall -Wextra -Werror -pedantic-errors):