Path: blob/main/contrib/llvm-project/libcxx/include/__expected/bad_expected_access.h
35262 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8#ifndef _LIBCPP___EXPECTED_BAD_EXPECTED_ACCESS_H9#define _LIBCPP___EXPECTED_BAD_EXPECTED_ACCESS_H1011#include <__config>12#include <__exception/exception.h>13#include <__utility/move.h>1415#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)16# pragma GCC system_header17#endif1819_LIBCPP_PUSH_MACROS20#include <__undef_macros>2122#if _LIBCPP_STD_VER >= 232324_LIBCPP_BEGIN_NAMESPACE_STD2526template <class _Err>27class bad_expected_access;2829_LIBCPP_DIAGNOSTIC_PUSH30# if !_LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION31_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wweak-vtables")32# endif33template <>34class _LIBCPP_EXPORTED_FROM_ABI bad_expected_access<void> : public exception {35protected:36_LIBCPP_HIDE_FROM_ABI bad_expected_access() noexcept = default;37_LIBCPP_HIDE_FROM_ABI bad_expected_access(const bad_expected_access&) noexcept = default;38_LIBCPP_HIDE_FROM_ABI bad_expected_access(bad_expected_access&&) noexcept = default;39_LIBCPP_HIDE_FROM_ABI bad_expected_access& operator=(const bad_expected_access&) noexcept = default;40_LIBCPP_HIDE_FROM_ABI bad_expected_access& operator=(bad_expected_access&&) noexcept = default;41_LIBCPP_HIDE_FROM_ABI_VIRTUAL ~bad_expected_access() override = default;4243public:44# if _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION45const char* what() const noexcept override;46# else47_LIBCPP_HIDE_FROM_ABI_VIRTUAL const char* what() const noexcept override { return "bad access to std::expected"; }48# endif49};50_LIBCPP_DIAGNOSTIC_POP5152template <class _Err>53class bad_expected_access : public bad_expected_access<void> {54public:55_LIBCPP_HIDE_FROM_ABI explicit bad_expected_access(_Err __e) : __unex_(std::move(__e)) {}5657_LIBCPP_HIDE_FROM_ABI _Err& error() & noexcept { return __unex_; }58_LIBCPP_HIDE_FROM_ABI const _Err& error() const& noexcept { return __unex_; }59_LIBCPP_HIDE_FROM_ABI _Err&& error() && noexcept { return std::move(__unex_); }60_LIBCPP_HIDE_FROM_ABI const _Err&& error() const&& noexcept { return std::move(__unex_); }6162private:63_Err __unex_;64};6566_LIBCPP_END_NAMESPACE_STD6768#endif // _LIBCPP_STD_VER >= 236970_LIBCPP_POP_MACROS7172#endif // _LIBCPP___EXPECTED_BAD_EXPECTED_ACCESS_H737475