Why is comparing two parameters of a constexpr function not a constant condition for static assertion?

前端 未结 1 1209
独厮守ぢ
独厮守ぢ 2020-12-06 12:49
constexpr uint32_t BitPositionToMask(int i,int Size){
static_assert(i < Size,\"bit position out of range\");
return 1 << i;
}

this generat

相关标签:
1条回答
  • 2020-12-06 13:44

    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.

    0 讨论(0)
提交回复
热议问题