为什么 Same<T, U> 不包含 Same<U, T>?
Why doesn't Same<T, U> subsume Same<U, T>?
在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>
)
是因为,
这就是为什么只有说明的概念 same-as-impl
在规范中是必要的。
在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>
)
是因为same-as-impl
在规范中是必要的。