相关疑难解决方法(0)

为什么 GCC 在使用 std::tuple_size::value 的约束上成功,但在使用 std::tuple_size_v 的约束上失败?

在下面的代码中,为什么第二个和第三个概念会产生编译错误?

#include <tuple>

template <class P>
concept IsPair1 = std::tuple_size<P>::value == 2;

template <class P>
concept IsPair2 = std::tuple_size_v<P> == 2;

template <class P>
concept IsPair3 = requires { typename std::tuple_size<P>; } && std::tuple_size_v<P> == 2;

constexpr bool intIsPair1 = IsPair1<int>;  // OK, false

constexpr bool intIsPair2 = IsPair2<int>;  // error: incomplete type 'std::tuple_size<int>' used in nested name specifier

constexpr bool intIsPair3 = IsPair3<int>;  // error: incomplete type 'std::tuple_size<int>' used in nested name specifier
Run Code Online (Sandbox Code Playgroud)
/usr/local/Cellar/gcc/11.1.0_1/include/c++/11.1.0/tuple:1334:61: error: incomplete type 'std::tuple_size<int>' used …
Run Code Online (Sandbox Code Playgroud)

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

2
推荐指数
1
解决办法
360
查看次数

标签 统计

c++ ×1

c++-concepts ×1

c++20 ×1