xref: /freebsd/contrib/llvm-project/libcxx/include/__variant/monostate.h (revision 0ad011ececb978e22a9bff2acf76633b094f1ff6)
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 <__functional/hash.h>
16 #include <cstddef>
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 _LIBCPP_TEMPLATE_VIS monostate {};
27 
28 _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(monostate, monostate) noexcept { return true; }
29 
30 #  if _LIBCPP_STD_VER >= 20
31 
32 _LIBCPP_HIDE_FROM_ABI 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 constexpr bool operator!=(monostate, monostate) noexcept { return false; }
39 
40 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(monostate, monostate) noexcept { return false; }
41 
42 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(monostate, monostate) noexcept { return false; }
43 
44 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(monostate, monostate) noexcept { return true; }
45 
46 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(monostate, monostate) noexcept { return true; }
47 
48 #  endif // _LIBCPP_STD_VER >= 20
49 
50 template <>
51 struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
52   using argument_type = monostate;
53   using result_type = size_t;
54 
55   inline _LIBCPP_HIDE_FROM_ABI result_type operator()(const argument_type&) const _NOEXCEPT {
56     return 66740831; // return a fundamentally attractive random value.
57   }
58 };
59 
60 #endif // _LIBCPP_STD_VER >= 17
61 
62 _LIBCPP_END_NAMESPACE_STD
63 
64 #endif // _LIBCPP___VARIANT_MONOSTATE_H
65