为什么std :: same_as以这种怪异的方式实现?

问题描述 投票:3回答:1

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>;
c++ standards c++20 c++-concepts language-implementation
1个回答
2
投票

这是句柄subsumption

,仅在概念上发生。
© www.soinside.com 2019 - 2024. All rights reserved.