Skip to content

Commit 41d6925

Browse files
Implement P0472R3 - Put monostate in <utility> (#5382)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent cdf1488 commit 41d6925

File tree

4 files changed

+41
-40
lines changed

4 files changed

+41
-40
lines changed

stl/inc/utility

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,46 @@ _NODISCARD _MSVC_INTRINSIC constexpr _Forward_like_t<_Ty, _Uty> forward_like(_Ut
973973
}
974974
#endif // _HAS_CXX23
975975

976+
#if _HAS_CXX17
977+
_EXPORT_STD struct monostate {};
978+
979+
_EXPORT_STD _NODISCARD constexpr bool operator==(monostate, monostate) noexcept {
980+
return true;
981+
}
982+
983+
#if _HAS_CXX20
984+
_EXPORT_STD _NODISCARD constexpr strong_ordering operator<=>(monostate, monostate) noexcept {
985+
return strong_ordering::equal;
986+
}
987+
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
988+
_NODISCARD constexpr bool operator!=(monostate, monostate) noexcept {
989+
return false;
990+
}
991+
_NODISCARD constexpr bool operator<(monostate, monostate) noexcept {
992+
return false;
993+
}
994+
_NODISCARD constexpr bool operator>(monostate, monostate) noexcept {
995+
return false;
996+
}
997+
_NODISCARD constexpr bool operator<=(monostate, monostate) noexcept {
998+
return true;
999+
}
1000+
_NODISCARD constexpr bool operator>=(monostate, monostate) noexcept {
1001+
return true;
1002+
}
1003+
#endif // ^^^ !_HAS_CXX20 ^^^
1004+
1005+
template <>
1006+
struct hash<monostate> {
1007+
using _ARGUMENT_TYPE_NAME _CXX17_DEPRECATE_ADAPTOR_TYPEDEFS = monostate;
1008+
using _RESULT_TYPE_NAME _CXX17_DEPRECATE_ADAPTOR_TYPEDEFS = size_t;
1009+
1010+
_NODISCARD _STATIC_CALL_OPERATOR size_t operator()(monostate) _CONST_CALL_OPERATOR noexcept {
1011+
return 1729; // Arbitrary value
1012+
}
1013+
};
1014+
#endif // _HAS_CXX17
1015+
9761016
#if _HAS_TR1_NAMESPACE
9771017
namespace _DEPRECATE_TR1_NAMESPACE tr1 {
9781018
using _STD get;

stl/inc/variant

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,32 +1647,6 @@ constexpr _Ret visit(_Callable&& _Obj, _Variants&&... _Args) {
16471647
}
16481648
#endif // _HAS_CXX20
16491649

1650-
_EXPORT_STD _NODISCARD constexpr bool operator==(monostate, monostate) noexcept {
1651-
return true;
1652-
}
1653-
1654-
#if _HAS_CXX20
1655-
_EXPORT_STD _NODISCARD constexpr strong_ordering operator<=>(monostate, monostate) noexcept {
1656-
return strong_ordering::equal;
1657-
}
1658-
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
1659-
_NODISCARD constexpr bool operator!=(monostate, monostate) noexcept {
1660-
return false;
1661-
}
1662-
_NODISCARD constexpr bool operator<(monostate, monostate) noexcept {
1663-
return false;
1664-
}
1665-
_NODISCARD constexpr bool operator>(monostate, monostate) noexcept {
1666-
return false;
1667-
}
1668-
_NODISCARD constexpr bool operator<=(monostate, monostate) noexcept {
1669-
return true;
1670-
}
1671-
_NODISCARD constexpr bool operator>=(monostate, monostate) noexcept {
1672-
return true;
1673-
}
1674-
#endif // ^^^ !_HAS_CXX20 ^^^
1675-
16761650
_EXPORT_STD template <class... _Types,
16771651
enable_if_t<conjunction_v<is_move_constructible<_Types>..., is_swappable<_Types>...>, int> = 0>
16781652
_CONSTEXPR20 void swap(variant<_Types...>& _Left, variant<_Types...>& _Right) noexcept(noexcept(_Left.swap(_Right))) {
@@ -1702,16 +1676,6 @@ struct hash<variant<_Types...>> : _Conditionally_enabled_hash<variant<_Types...>
17021676
}
17031677
};
17041678

1705-
template <>
1706-
struct hash<monostate> {
1707-
using _ARGUMENT_TYPE_NAME _CXX17_DEPRECATE_ADAPTOR_TYPEDEFS = monostate;
1708-
using _RESULT_TYPE_NAME _CXX17_DEPRECATE_ADAPTOR_TYPEDEFS = size_t;
1709-
1710-
_NODISCARD _STATIC_CALL_OPERATOR size_t operator()(monostate) _CONST_CALL_OPERATOR noexcept {
1711-
return 1729; // Arbitrary value
1712-
}
1713-
};
1714-
17151679
_STD_END
17161680

17171681
#undef _STL_STAMP

stl/inc/xutility

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7561,10 +7561,6 @@ struct _CXX17_DEPRECATE_ITERATOR_BASE_CLASS iterator { // base type for iterator
75617561
using reference = _Reference;
75627562
};
75637563

7564-
#if _HAS_CXX17
7565-
_EXPORT_STD struct monostate {};
7566-
#endif // _HAS_CXX17
7567-
75687564
#if _HAS_CXX23
75697565
template <_Integer_like _Int>
75707566
_NODISCARD constexpr bool _Add_overflow(const _Int _Left, const _Int _Right, _Int& _Out) {

stl/inc/yvals_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
// P0426R1 constexpr For char_traits
121121
// P0433R2 Deduction Guides For The STL
122122
// P0452R1 Unifying <numeric> Parallel Algorithms
123+
// P0472R3 Put monostate In <utility>
123124
// P0504R0 Revisiting in_place_t/in_place_type_t<T>/in_place_index_t<I>
124125
// P0505R0 constexpr For <chrono> (Again)
125126
// P0508R0 Clarifying insert_return_type

0 commit comments

Comments
 (0)