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 <__config>
14 #include <__functional/hash.h>
15 #include <cstddef>
16 
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #  pragma GCC system_header
19 #endif
20 
21 _LIBCPP_BEGIN_NAMESPACE_STD
22 
23 #if _LIBCPP_STD_VER > 14
24 
25 struct _LIBCPP_TEMPLATE_VIS monostate {};
26 
27 inline _LIBCPP_INLINE_VISIBILITY
28 constexpr bool operator<(monostate, monostate) noexcept { return false; }
29 
30 inline _LIBCPP_INLINE_VISIBILITY
31 constexpr bool operator>(monostate, monostate) noexcept { return false; }
32 
33 inline _LIBCPP_INLINE_VISIBILITY
34 constexpr bool operator<=(monostate, monostate) noexcept { return true; }
35 
36 inline _LIBCPP_INLINE_VISIBILITY
37 constexpr bool operator>=(monostate, monostate) noexcept { return true; }
38 
39 inline _LIBCPP_INLINE_VISIBILITY
40 constexpr bool operator==(monostate, monostate) noexcept { return true; }
41 
42 inline _LIBCPP_INLINE_VISIBILITY
43 constexpr bool operator!=(monostate, monostate) noexcept { return false; }
44 
45 template <>
46 struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
47   using argument_type = monostate;
48   using result_type = size_t;
49 
50   inline _LIBCPP_INLINE_VISIBILITY
51   result_type operator()(const argument_type&) const _NOEXCEPT {
52     return 66740831; // return a fundamentally attractive random value.
53   }
54 };
55 
56 #endif // _LIBCPP_STD_VER > 14
57 
58 _LIBCPP_END_NAMESPACE_STD
59 
60 #endif // _LIBCPP___VARIANT_MONOSTATE_H
61