| 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_COMMON_H |
| 11 | #define _LIBCPP___OPTIONAL_COMMON_H |
| 12 | |
| 13 | #include <__assert> |
| 14 | #include <__config> |
| 15 | #include <__exception/exception.h> |
| 16 | #include <__fwd/format.h> |
| 17 | #include <__ranges/enable_borrowed_range.h> |
| 18 | #include <__ranges/enable_view.h> |
| 19 | #include <__type_traits/is_object.h> |
| 20 | #include <__type_traits/is_reference.h> |
| 21 | #include <__verbose_abort> |
| 22 | |
| 23 | #include <__fwd/optional.h> |
| 24 | |
| 25 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 26 | # pragma GCC system_header |
| 27 | #endif |
| 28 | |
| 29 | _LIBCPP_PUSH_MACROS |
| 30 | #include <__undef_macros> |
| 31 | |
| 32 | namespace std // purposefully not using versioning namespace |
| 33 | { |
| 34 | |
| 35 | class _LIBCPP_EXPORTED_FROM_ABI bad_optional_access : public exception { |
| 36 | public: |
| 37 | _LIBCPP_HIDE_FROM_ABI bad_optional_access() _NOEXCEPT = default; |
| 38 | _LIBCPP_HIDE_FROM_ABI bad_optional_access(const bad_optional_access&) _NOEXCEPT = default; |
| 39 | _LIBCPP_HIDE_FROM_ABI bad_optional_access& operator=(const bad_optional_access&) _NOEXCEPT = default; |
| 40 | // Get the key function ~bad_optional_access() into the dylib |
| 41 | ~bad_optional_access() _NOEXCEPT override; |
| 42 | [[__nodiscard__]] const char* what() const _NOEXCEPT override; |
| 43 | }; |
| 44 | |
| 45 | } // namespace std |
| 46 | |
| 47 | #if _LIBCPP_STD_VER >= 17 |
| 48 | |
| 49 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 50 | |
| 51 | [[noreturn]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_optional_access() { |
| 52 | # if _LIBCPP_HAS_EXCEPTIONS |
| 53 | throw bad_optional_access(); |
| 54 | # else |
| 55 | _LIBCPP_VERBOSE_ABORT("bad_optional_access was thrown in -fno-exceptions mode"); |
| 56 | # endif |
| 57 | } |
| 58 | |
| 59 | struct __optional_construct_from_invoke_tag {}; |
| 60 | |
| 61 | template <class _Tp> |
| 62 | inline constexpr bool __is_std_optional_v = false; |
| 63 | |
| 64 | template <class _Tp> |
| 65 | inline constexpr bool __is_std_optional_v<optional<_Tp>> = true; |
| 66 | |
| 67 | # if _LIBCPP_STD_VER < 26 |
| 68 | template <class _Tp> |
| 69 | inline constexpr bool __is_valid_optional_contained_type = is_object_v<_Tp>; |
| 70 | # else |
| 71 | template <class _Tp> |
| 72 | inline constexpr bool __is_valid_optional_contained_type = is_object_v<_Tp> || is_lvalue_reference_v<_Tp>; |
| 73 | # endif |
| 74 | |
| 75 | # if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPERIMENTAL_OPTIONAL_ITERATOR |
| 76 | |
| 77 | template <class _Tp> |
| 78 | constexpr bool ranges::enable_view<optional<_Tp>> = true; |
| 79 | |
| 80 | template <class _Tp> |
| 81 | constexpr range_format format_kind<optional<_Tp>> = range_format::disabled; |
| 82 | |
| 83 | template <class _Tp> |
| 84 | constexpr bool ranges::enable_borrowed_range<optional<_Tp&>> = true; |
| 85 | |
| 86 | # endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPERIMENTAL_OPTIONAL_ITERATOR |
| 87 | |
| 88 | _LIBCPP_END_NAMESPACE_STD |
| 89 | |
| 90 | #endif // _LIBCPP_STD_VER >= 17 |
| 91 | |
| 92 | _LIBCPP_POP_MACROS |
| 93 | |
| 94 | #endif // _LIBCPP___OPTIONAL_COMMON_H |
| 95 |