相关疑难解决方法(0)

临时约束需要需要需要需要吗?

假设我正在编写一个类模板,其中一些成员受到类型模板参数 static constexpr 数据成员的存在和值的限制:

\n
template<class T>\nstruct A {\n    constexpr bool operator()() requires T::value { return T::value; }\n    constexpr bool operator()() { return false; }\n};\n#include <type_traits>\nstatic_assert(A<std::true_type>()());\nstatic_assert(!A<std::false_type>()());\nstatic_assert(!A<void>()());\n
Run Code Online (Sandbox Code Playgroud)\n

MSVC 和 gcc 接受这一点,但 clang 拒绝,除非我替换 requires T::valuerequires requires { requires T::value; }. 这是 clang 中的错误,还是其他编译器松懈?C++ 是否需要需要需要需要?标准怎么说?

\n

相关(嗯,至少是\xe2\x85\x94):为什么我们需要需要需要?

\n

c++ compiler-errors language-lawyer c++-concepts c++20

6
推荐指数
1
解决办法
384
查看次数