Comparing constexpr function parameter in constexpr-if condition causes error

前端 未结 2 630
轮回少年
轮回少年 2020-12-12 02:41

I\'m trying to compare a function parameter inside a constexpr-if statement.

Here is a simple example:

constexpr bool test_int(const int i) {
  if c         


        
2条回答
  •  既然无缘
    2020-12-12 03:27

    A constexpr function can be called with non-constexpr arguments, in which case it behaves like a normal function, so the code must still compile as if it were not constexpr.

    In short, there's nothing in test_int_no_if that depends on i being constexpr, while in test_int(), there is. ("constexpr if" only works with compile time expressions.)

提交回复
热议问题