|
|
|
|
|
by gpderetta
80 days ago
|
|
First of all mem::transmute is like bit_cast (which works perfectly fine in constexpr context), not reinterpret cast. Second, this compiles just fine: constexpr int ivalue = 1;
constexpr bool bvalue {ivalue};
This fails at compile time (invalid narrowing): constexpr int ivalue = 2;
constexpr bool bvalue {ivalue};
Note we don't need bit_cast for this example as int to bool conversions are allowed in C++. |
|
I see that C++ people were more comfortable with the "We have far too many ways to initialize things" examples of this problem but I think transmutation hits harder precisely because it sneaks up on you.