Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 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 | |
Kent Ross | c4566ca | 2022-08-14 23:14:57 | [diff] [blame] | 13 | #include <__compare/ordering.h> |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 14 | #include <__config> |
Nikolas Klauser | e99c490 | 2024-10-31 01:20:10 | [diff] [blame^] | 15 | #include <__cstddef/size_t.h> |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 16 | #include <__functional/hash.h> |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 17 | |
| 18 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | fa6b9e4 | 2022-02-02 01:16:40 | [diff] [blame] | 19 | # pragma GCC system_header |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 20 | #endif |
| 21 | |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 22 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 23 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 24 | #if _LIBCPP_STD_VER >= 17 |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 25 | |
| 26 | struct _LIBCPP_TEMPLATE_VIS monostate {}; |
| 27 | |
Louis Dionne | b81c694 | 2023-12-13 15:17:27 | [diff] [blame] | 28 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(monostate, monostate) noexcept { return true; } |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 29 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 30 | # if _LIBCPP_STD_VER >= 20 |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 31 | |
Louis Dionne | b81c694 | 2023-12-13 15:17:27 | [diff] [blame] | 32 | _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(monostate, monostate) noexcept { |
Kent Ross | c4566ca | 2022-08-14 23:14:57 | [diff] [blame] | 33 | return strong_ordering::equal; |
| 34 | } |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 35 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 36 | # else // _LIBCPP_STD_VER >= 20 |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 37 | |
Louis Dionne | b81c694 | 2023-12-13 15:17:27 | [diff] [blame] | 38 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator!=(monostate, monostate) noexcept { return false; } |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 39 | |
Louis Dionne | b81c694 | 2023-12-13 15:17:27 | [diff] [blame] | 40 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<(monostate, monostate) noexcept { return false; } |
Kent Ross | c4566ca | 2022-08-14 23:14:57 | [diff] [blame] | 41 | |
Louis Dionne | b81c694 | 2023-12-13 15:17:27 | [diff] [blame] | 42 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>(monostate, monostate) noexcept { return false; } |
Kent Ross | c4566ca | 2022-08-14 23:14:57 | [diff] [blame] | 43 | |
Louis Dionne | b81c694 | 2023-12-13 15:17:27 | [diff] [blame] | 44 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<=(monostate, monostate) noexcept { return true; } |
Kent Ross | c4566ca | 2022-08-14 23:14:57 | [diff] [blame] | 45 | |
Louis Dionne | b81c694 | 2023-12-13 15:17:27 | [diff] [blame] | 46 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(monostate, monostate) noexcept { return true; } |
Kent Ross | c4566ca | 2022-08-14 23:14:57 | [diff] [blame] | 47 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 48 | # endif // _LIBCPP_STD_VER >= 20 |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 49 | |
| 50 | template <> |
| 51 | struct _LIBCPP_TEMPLATE_VIS hash<monostate> { |
| 52 | using argument_type = monostate; |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 53 | using result_type = size_t; |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 54 | |
Kent Ross | c4566ca | 2022-08-14 23:14:57 | [diff] [blame] | 55 | inline _LIBCPP_HIDE_FROM_ABI result_type operator()(const argument_type&) const _NOEXCEPT { |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 56 | return 66740831; // return a fundamentally attractive random value. |
| 57 | } |
| 58 | }; |
| 59 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 60 | #endif // _LIBCPP_STD_VER >= 17 |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 61 | |
| 62 | _LIBCPP_END_NAMESPACE_STD |
| 63 | |
Mark de Wever | 321c2ea | 2021-07-07 19:27:27 | [diff] [blame] | 64 | #endif // _LIBCPP___VARIANT_MONOSTATE_H |