gpt4 book ai didi

c++ - Same 为什么不包含Same

转载 作者:行者123 更新时间:2023-12-01 14:43:27 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com