c++ - 为什么 Same<T, U> 不包含 Same<U, T>?

标签 c++ c++-standard-library c++20 c++-concepts

LWG 3182 ,它指出

The specification of the Same concept in 18.4.2 [concept.same]:

template<class T, class U>
  concept Same = is_same_v<T, U>;

-1- Same<T, U> subsumes Same<U, T> and vice versa.

seems contradictory. From the concept definition alone, it is not the case that Same<T, U> subsumes Same<U, T> nor vice versa.

但是,从 cppreference ,

... Commutativity is satisfied, i.e. for any two types T and U, is_same<T, U>::value == true if and only if is_same<U, T>::value == true.

注意Same<T, U>定义为is_same_v<T, U> ,怎么能Same<T, U>不包含Same<U, T>

最佳答案

该问题提到了标准概念Same ,已重命名为 same_as ,并通过以下方式解决 将其指定为 [concept.same] :

 template<class T, class U>
   concept same-as-impl = is_same_v<T, U>;       // exposition only

 template<class T, class U>
   concept same_as = same-as-impl<T, U> && same-as-impl<U, T>;

简单定义不对称的原因(即 Same<T, U> 不包含 Same<U, T> ) 是因为only concepts can be subsumed , 这就是为什么仅展示概念 same-as-impl在规范中是必需的。

关于c++ - 为什么 Same<T, U> 不包含 Same<U, T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60145452/

相关文章:

c++ - 为什么 std::count 和 std::find 没有优化为使用 memchr?

c++ - 双向关联容器

c++ - 静态模板数据成员存储

c++ - Visual Studio 2010 不会自动链接来自依赖项的项目中的静态库,因为它应该是

c++ - add_lvalue_reference/add_rvalue_reference 和 cv 限定类型

c++ - constexpr new 如何分配内存?

c++ - 为什么在 hana::中包装对按值返回的函数的调用总是规避 range::views::join 的要求?或者也许不是?

c++ - std::invocable 和 std::regular_invocable 概念之间有什么区别?

c++ - 为每个节点定义一个唯一的整数

C++ "Could not convert ' 类实例'从 'Class (*)()' 到 'Class' ”