为什么保守函数表达式不是主表达式?

问题描述 投票:0回答:1

考虑以下代码片段(使用 clang19 编译):

consteval bool IsEven(int n) {
    return 0 == n % 2;
}
   
template<int n>
requires (IsEven(n)) // ok
void f1() {}

template<int n>
requires IsEven(n) // error: Atomic constraint must be of type 'bool'
                   // (found '<overloaded function type>')
void f2() {}

cppref 页面告诉我

IsEven(n)
不是主要表达式。我只是想知道:

为什么保守函数表达式 NOT 是主要表达式?

c++ c++20 standards c++-concepts type-constraints
1个回答
0
投票

这与 consteval 或您收到的错误消息没有任何关系。主表达式只是表达式的语法类别,函数调用不属于该类别。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.