c++ - 为什么 std::same_as 以如此奇怪的方式实现?

标签 c++ standards c++20 c++-concepts language-implementation

这个问题在这里已经有了答案:





Why does same_as concept check type equality twice?

(3 个回答)


去年关闭。




cppref给出了 std::same_as 的可能实现:

namespace detail {
    template<class T, class U>
    concept SameHelper = std::is_same_v<T, U>;
}

template<class T, class U>
concept same_as = detail::SameHelper<T, U> && detail::SameHelper<U, T>;

为什么不执行如下:
template<class T, class U>
concept same_as = std::is_same_v<T, U> && std::is_same_v<U, T>;

甚至更短:
template<class T, class U>
concept same_as = std::is_same_v<T, U>;

最佳答案

是t把包容这只发生在概念上。

有了你的提议,
same_as<T, U>不包含 same_as<U, T> .

进一步阅读 cppreference .

关于c++ - 为什么 std::same_as 以如此奇怪的方式实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61056470/

相关文章:

c++ - 关于CUDA中的固定内存,它有上限吗?

c++ - "only one implementation"规则的异常(exception)?

c++ - 具有类类型非类型模板参数的类模板成员的类外定义

node.js - 在 Node.js 中声明变量的最佳方式

c++ - span 可以是 constexpr 吗?

c++ - 函数输入参数的 auto 是否可以替代函数模板?

c++ - 在 C++ 中删除多余的空格

c++ - 如何在 Qt Creator 中设置 “set a breakpoint in malloc_error_break to debug”?

java - 可见性标准的解释(尤其是 Java 与 UML)

c - C 标准草案 (n1256.pdf) 的 HTML 版本?