Add mstd::is_constant_evaluated
GCC 9 and sufficiently-new Clang (including ARM Compiler 6.13) give us access to the C++20 (draft) `is_constant_evaluated` test. Allows us to restrict code to compile-time only. This is particularly useful when using assembler intrinsics, which the compiler cannot optimise or compile-time evaluate. It allows us to write something like constexpr uint32_t reverse_bits(uint32_t x) { if (is_constant_evaluated(x)) { // C code to do calculation here return x; } else { // an assembler intrinsic that cannot be optimised return __RBIT(x); } } This can then be totally compile-time given a constant input. (In this example, ultimately it would be a good idea to include this functionality in CMSIS's GCC `__RBIT`, which needs it because GCC requires use of assembler. Clang implements `__RBIT` as a built-in, meaning it can already compute it at compile-time, so does not benefit.). |
---|
|
platform/cxxsupport/mstd_type_traits |
---|