constexpr uint32_t BitPositionToMask(int i,int Size){
static_assert(i < Size,\"bit position out of range\");
return 1 << i;
}
this generat
A constexpr
function can also be invoked with arguments evaluated at run-time (in that case, it just gets executed just like any regular function). See, for instance, this live example.
A static_assert()
, on the other hand, strictly requires its condition to be a constant expression that can be evaluated at compile time.