小编can*_*yme的帖子

为什么不同的编译器对这些 require 表达式的行为不同?

为什么 C++ 20 中使用 require 表达式的“Oneable”概念的某些实现无法在某些编译器上编译?

// `Oneable` implemented using `requires` with a simple assignment expression

// clang, gcc, and msvc all compile

template <class T>
concept Oneable = requires(T n) { n = 1; };

static_assert(Oneable<int>);
static_assert(!Oneable<int*>);
Run Code Online (Sandbox Code Playgroud)
// `Oneable` implemented using `requires` with an assignment statement inside
// the body of a lambda expression

// clang and msvc compile
// gcc gives a compiler error on instantiating Oneable<T*>

template <class T>
concept Oneable = requires { []() { T …
Run Code Online (Sandbox Code Playgroud)

c++ c++-concepts c++20

19
推荐指数
1
解决办法
1281
查看次数

标签 统计

c++ ×1

c++-concepts ×1

c++20 ×1