Hide std::unreachable_sentinel_t's friends harder (#352)

Hidden friends aren't hidden in C1XX's permissive mode, so let's use an alternate mechanism to make these operators truly ADL-only. (We want to avoid checking `weakly_incrementable` for every type that is compared via `==` or `!=` with a type associated with namespace `std`.)
This commit is contained in:
Casey Carter 2019-12-04 20:20:56 -08:00 коммит произвёл Stephan T. Lavavej
Родитель 40017205af
Коммит d42d1cd2a5
1 изменённых файлов: 22 добавлений и 18 удалений

Просмотреть файл

@ -3548,27 +3548,31 @@ struct default_sentinel_t {};
inline constexpr default_sentinel_t default_sentinel{};
// STRUCT unreachable_sentinel_t
struct unreachable_sentinel_t {
template <weakly_incrementable _Winc>
_NODISCARD friend constexpr bool operator==(unreachable_sentinel_t, const _Winc&) noexcept {
return false;
}
struct unreachable_sentinel_t;
namespace _Unreachable_sentinel_detail {
struct _Base {
template <weakly_incrementable _Winc>
_NODISCARD friend constexpr bool operator==(unreachable_sentinel_t, const _Winc&) noexcept {
return false;
}
#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
template <weakly_incrementable _Winc>
_NODISCARD friend constexpr bool operator==(const _Winc&, unreachable_sentinel_t) noexcept {
return false;
}
template <weakly_incrementable _Winc>
_NODISCARD friend constexpr bool operator==(const _Winc&, unreachable_sentinel_t) noexcept {
return false;
}
template <weakly_incrementable _Winc>
_NODISCARD friend constexpr bool operator!=(unreachable_sentinel_t, const _Winc&) noexcept {
return true;
}
template <weakly_incrementable _Winc>
_NODISCARD friend constexpr bool operator!=(const _Winc&, unreachable_sentinel_t) noexcept {
return true;
}
template <weakly_incrementable _Winc>
_NODISCARD friend constexpr bool operator!=(unreachable_sentinel_t, const _Winc&) noexcept {
return true;
}
template <weakly_incrementable _Winc>
_NODISCARD friend constexpr bool operator!=(const _Winc&, unreachable_sentinel_t) noexcept {
return true;
}
#endif // !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
};
};
} // namespace _Unreachable_sentinel_detail
struct unreachable_sentinel_t : _Unreachable_sentinel_detail::_Base {}; // TRANSITION, /permissive-
// VARIABLE unreachable_sentinel
inline constexpr unreachable_sentinel_t unreachable_sentinel{};