File indexing completed on 2026-05-03 08:13:26
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___EXPECTED_BAD_EXPECTED_ACCESS_H
0010 #define _LIBCPP___CXX03___EXPECTED_BAD_EXPECTED_ACCESS_H
0011
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__exception/exception.h>
0014 #include <__cxx03/__utility/move.h>
0015
0016 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0017 # pragma GCC system_header
0018 #endif
0019
0020 _LIBCPP_PUSH_MACROS
0021 #include <__cxx03/__undef_macros>
0022
0023 #if _LIBCPP_STD_VER >= 23
0024
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026
0027 template <class _Err>
0028 class bad_expected_access;
0029
0030 _LIBCPP_DIAGNOSTIC_PUSH
0031 # if !_LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION
0032 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wweak-vtables")
0033 # endif
0034 template <>
0035 class _LIBCPP_EXPORTED_FROM_ABI bad_expected_access<void> : public exception {
0036 protected:
0037 _LIBCPP_HIDE_FROM_ABI bad_expected_access() noexcept = default;
0038 _LIBCPP_HIDE_FROM_ABI bad_expected_access(const bad_expected_access&) noexcept = default;
0039 _LIBCPP_HIDE_FROM_ABI bad_expected_access(bad_expected_access&&) noexcept = default;
0040 _LIBCPP_HIDE_FROM_ABI bad_expected_access& operator=(const bad_expected_access&) noexcept = default;
0041 _LIBCPP_HIDE_FROM_ABI bad_expected_access& operator=(bad_expected_access&&) noexcept = default;
0042 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~bad_expected_access() override = default;
0043
0044 public:
0045 # if _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION
0046 const char* what() const noexcept override;
0047 # else
0048 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const char* what() const noexcept override { return "bad access to std::expected"; }
0049 # endif
0050 };
0051 _LIBCPP_DIAGNOSTIC_POP
0052
0053 template <class _Err>
0054 class bad_expected_access : public bad_expected_access<void> {
0055 public:
0056 _LIBCPP_HIDE_FROM_ABI explicit bad_expected_access(_Err __e) : __unex_(std::move(__e)) {}
0057
0058 _LIBCPP_HIDE_FROM_ABI _Err& error() & noexcept { return __unex_; }
0059 _LIBCPP_HIDE_FROM_ABI const _Err& error() const& noexcept { return __unex_; }
0060 _LIBCPP_HIDE_FROM_ABI _Err&& error() && noexcept { return std::move(__unex_); }
0061 _LIBCPP_HIDE_FROM_ABI const _Err&& error() const&& noexcept { return std::move(__unex_); }
0062
0063 private:
0064 _Err __unex_;
0065 };
0066
0067 _LIBCPP_END_NAMESPACE_STD
0068
0069 #endif
0070
0071 _LIBCPP_POP_MACROS
0072
0073 #endif