VCCC  2024.05
VisualCamp Common C++ library
bad_expected_access.hpp
Go to the documentation of this file.
1 //
2 // Created by YongGyu Lee on 3/20/24.
3 //
4 
5 #ifndef VCCC_EXPECTED_BAD_EXPECTED_ACCESS_HPP_
6 #define VCCC_EXPECTED_BAD_EXPECTED_ACCESS_HPP_
7 
8 #include <exception>
9 #include <utility>
10 
11 namespace vccc {
12 
15 
16 template<typename E>
17 class bad_expected_access;
18 
19 template<>
20 class bad_expected_access<void> : public std::exception {
21  public:
22  const char* what() const noexcept override {
23  return "vccc::bad_expected_access";
24  }
25 
26  protected:
27  bad_expected_access() noexcept = default;
30  bad_expected_access& operator=(const bad_expected_access&) = default;
31  bad_expected_access& operator=(bad_expected_access&&) = default;
32 };
33 
34 template<typename E>
36  public:
37  explicit bad_expected_access(E e)
38  : error_(std::move(e)) {}
39 
40  const E& error() const& noexcept { return error_; }
41  E& error() & noexcept { return error_; }
42  const E&& error() const&& noexcept { return std::move(error_); }
43  E&& error() && noexcept { return std::move(error_); }
44 
45  private:
46  E error_;
47 };
48 
50 
51 } // namespace vccc
52 
53 #endif // VCCC_EXPECTED_BAD_EXPECTED_ACCESS_HPP_
bad_expected_access() noexcept=default
const char * what() const noexcept override
Definition: bad_expected_access.hpp:22
Definition: bad_expected_access.hpp:35
bad_expected_access(E e)
Definition: bad_expected_access.hpp:37
const E && error() const &&noexcept
Definition: bad_expected_access.hpp:42
E && error() &&noexcept
Definition: bad_expected_access.hpp:43
E & error() &noexcept
Definition: bad_expected_access.hpp:41
const E & error() const &noexcept
Definition: bad_expected_access.hpp:40
constexpr T e
the mathematical constant
Definition: constants.hpp:37
Definition: matrix.hpp:495
Definition: directory.h:12