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