在 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>
subsumesSame<U, T>
nor vice versa.
但是,从 cppreference ,
... Commutativity is satisfied, i.e. for any two types
T
andU
,is_same<T, U>::value == true
if and only ifis_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/