xref: /freebsd/contrib/llvm-project/libcxx/include/__variant/monostate.h (revision 13ec1e3155c7e9bf037b12af186351b7fa9b9450)
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_PUSH_MACROS
22 #include <__undef_macros>
23 
24 _LIBCPP_BEGIN_NAMESPACE_STD
25 
26 #if _LIBCPP_STD_VER > 14
27 
28 struct _LIBCPP_TEMPLATE_VIS monostate {};
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 false; }
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 true; }
44 
45 inline _LIBCPP_INLINE_VISIBILITY
46 constexpr bool operator!=(monostate, monostate) noexcept { return false; }
47 
48 template <>
49 struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
50   using argument_type = monostate;
51   using result_type = size_t;
52 
53   inline _LIBCPP_INLINE_VISIBILITY
54   result_type operator()(const argument_type&) const _NOEXCEPT {
55     return 66740831; // return a fundamentally attractive random value.
56   }
57 };
58 
59 #endif // _LIBCPP_STD_VER > 14
60 
61 _LIBCPP_END_NAMESPACE_STD
62 
63 _LIBCPP_POP_MACROS
64 
65 #endif // _LIBCPP___VARIANT_MONOSTATE_H
66