monostate.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #ifndef _LIBCPP___VARIANT_MONOSTATE_H
  10. #define _LIBCPP___VARIANT_MONOSTATE_H
  11. #include <__config>
  12. #include <__functional/hash.h>
  13. #include <cstddef>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. #if _LIBCPP_STD_VER > 14
  19. struct _LIBCPP_TEMPLATE_VIS monostate {};
  20. inline _LIBCPP_INLINE_VISIBILITY
  21. constexpr bool operator<(monostate, monostate) noexcept { return false; }
  22. inline _LIBCPP_INLINE_VISIBILITY
  23. constexpr bool operator>(monostate, monostate) noexcept { return false; }
  24. inline _LIBCPP_INLINE_VISIBILITY
  25. constexpr bool operator<=(monostate, monostate) noexcept { return true; }
  26. inline _LIBCPP_INLINE_VISIBILITY
  27. constexpr bool operator>=(monostate, monostate) noexcept { return true; }
  28. inline _LIBCPP_INLINE_VISIBILITY
  29. constexpr bool operator==(monostate, monostate) noexcept { return true; }
  30. inline _LIBCPP_INLINE_VISIBILITY
  31. constexpr bool operator!=(monostate, monostate) noexcept { return false; }
  32. template <>
  33. struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
  34. using argument_type = monostate;
  35. using result_type = size_t;
  36. inline _LIBCPP_INLINE_VISIBILITY
  37. result_type operator()(const argument_type&) const _NOEXCEPT {
  38. return 66740831; // return a fundamentally attractive random value.
  39. }
  40. };
  41. #endif // _LIBCPP_STD_VER > 14
  42. _LIBCPP_END_NAMESPACE_STD
  43. #endif // _LIBCPP___VARIANT_MONOSTATE_H