123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #ifndef BOOST_OUTCOME_POLICY_THROW_BAD_RESULT_ACCESS_HPP
- #define BOOST_OUTCOME_POLICY_THROW_BAD_RESULT_ACCESS_HPP
- #include "../bad_access.hpp"
- #include "base.hpp"
- BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
- namespace policy
- {
-
- template <class EC, class EP> struct throw_bad_result_access : base
- {
- template <class Impl> static constexpr void wide_value_check(Impl &&self)
- {
- if(!base::_has_value(std::forward<Impl>(self)))
- {
- BOOST_OUTCOME_THROW_EXCEPTION(bad_outcome_access("no value"));
- }
- }
- template <class Impl> static constexpr void wide_error_check(Impl &&self)
- {
- if(!base::_has_error(std::forward<Impl>(self)))
- {
- BOOST_OUTCOME_THROW_EXCEPTION(bad_outcome_access("no error"));
- }
- }
- template <class Impl> static constexpr void wide_exception_check(Impl &&self)
- {
- if(!base::_has_exception(std::forward<Impl>(self)))
- {
- BOOST_OUTCOME_THROW_EXCEPTION(bad_outcome_access("no exception"));
- }
- }
- };
- template <class EC> struct throw_bad_result_access<EC, void> : base
- {
- template <class Impl> static constexpr void wide_value_check(Impl &&self)
- {
- if(!base::_has_value(std::forward<Impl>(self)))
- {
- if(base::_has_error(std::forward<Impl>(self)))
- {
- BOOST_OUTCOME_THROW_EXCEPTION(bad_result_access_with<EC>(base::_error(std::forward<Impl>(self))));
- }
- BOOST_OUTCOME_THROW_EXCEPTION(bad_result_access("no value"));
- }
- }
- template <class Impl> static constexpr void wide_error_check(Impl &&self)
- {
- if(!base::_has_error(std::forward<Impl>(self)))
- {
- BOOST_OUTCOME_THROW_EXCEPTION(bad_result_access("no error"));
- }
- }
- };
- }
- BOOST_OUTCOME_V2_NAMESPACE_END
- #endif
|