| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___VARIANT_MONOSTATE_H |
| 11 | #define _LIBCPP___VARIANT_MONOSTATE_H |
| 12 | |
| 13 | #include <__compare/ordering.h> |
| 14 | #include <__config> |
| 15 | #include <__cstddef/size_t.h> |
| 16 | #include <__functional/hash.h> |
| 17 | |
| 18 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 19 | # pragma GCC system_header |
| 20 | #endif |
| 21 | |
| 22 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 23 | |
| 24 | #if _LIBCPP_STD_VER >= 17 |
| 25 | |
| 26 | struct monostate {}; |
| 27 | |
| 28 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(monostate, monostate) noexcept { return true; } |
| 29 | |
| 30 | # if _LIBCPP_STD_VER >= 20 |
| 31 | |
| 32 | _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(monostate, monostate) noexcept { |
| 33 | return strong_ordering::equal; |
| 34 | } |
| 35 | |
| 36 | # else // _LIBCPP_STD_VER >= 20 |
| 37 | |
| 38 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator!=(monostate, monostate) noexcept { return false; } |
| 39 | |
| 40 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<(monostate, monostate) noexcept { return false; } |
| 41 | |
| 42 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>(monostate, monostate) noexcept { return false; } |
| 43 | |
| 44 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<=(monostate, monostate) noexcept { return true; } |
| 45 | |
| 46 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(monostate, monostate) noexcept { return true; } |
| 47 | |
| 48 | # endif // _LIBCPP_STD_VER >= 20 |
| 49 | |
| 50 | template <> |
| 51 | struct hash<monostate> { |
| 52 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 53 | using argument_type _LIBCPP_DEPRECATED_IN_CXX17 = monostate; |
| 54 | using result_type _LIBCPP_DEPRECATED_IN_CXX17 = size_t; |
| 55 | # endif |
| 56 | |
| 57 | inline _LIBCPP_HIDE_FROM_ABI size_t operator()(const monostate&) const noexcept { |
| 58 | return 66740831; // return a fundamentally attractive random value. |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | #endif // _LIBCPP_STD_VER >= 17 |
| 63 | |
| 64 | _LIBCPP_END_NAMESPACE_STD |
| 65 | |
| 66 | #endif // _LIBCPP___VARIANT_MONOSTATE_H |
| 67 | |