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