| 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___OPTIONAL_NULLOPT_T_H |
| 11 | #define _LIBCPP___OPTIONAL_NULLOPT_T_H |
| 12 | |
| 13 | #include <__compare/ordering.h> |
| 14 | #include <__config> |
| 15 | |
| 16 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 17 | # pragma GCC system_header |
| 18 | #endif |
| 19 | |
| 20 | _LIBCPP_PUSH_MACROS |
| 21 | #include <__undef_macros> |
| 22 | |
| 23 | #if _LIBCPP_STD_VER >= 17 |
| 24 | |
| 25 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 26 | |
| 27 | struct nullopt_t { |
| 28 | struct __secret_tag { |
| 29 | explicit __secret_tag() = default; |
| 30 | }; |
| 31 | _LIBCPP_HIDE_FROM_ABI constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {} |
| 32 | |
| 33 | # if _LIBCPP_STD_VER >= 20 |
| 34 | |
| 35 | _LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering operator<=>(nullopt_t, nullopt_t) = default; |
| 36 | |
| 37 | # else |
| 38 | |
| 39 | _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator==(nullopt_t, nullopt_t) noexcept { return true; } |
| 40 | _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator!=(nullopt_t, nullopt_t) noexcept { return false; } |
| 41 | _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator>(nullopt_t, nullopt_t) noexcept { return false; } |
| 42 | _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator<(nullopt_t, nullopt_t) noexcept { return false; } |
| 43 | _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator>=(nullopt_t, nullopt_t) noexcept { return true; } |
| 44 | _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator<=(nullopt_t, nullopt_t) noexcept { return true; } |
| 45 | |
| 46 | # endif // _LIBCPP_STD_VER >= 20 |
| 47 | }; |
| 48 | |
| 49 | inline constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}}; |
| 50 | |
| 51 | _LIBCPP_END_NAMESPACE_STD |
| 52 | |
| 53 | #endif // _LIBCPP_STD_VER >= 17 |
| 54 | |
| 55 | _LIBCPP_POP_MACROS |
| 56 | #endif // _LIBCPP___OPTIONAL_NULLOPT_T_H |
| 57 | |