123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #ifndef BOOST_OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
- #define BOOST_OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
- #include "basic_result_storage.hpp"
- #include <exception>
- BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
- namespace detail
- {
- namespace adl
- {
- struct search_detail_adl
- {
- };
-
- template <class S, typename = decltype(basic_outcome_failure_exception_from_error(std::declval<S>()))>
- inline auto _delayed_lookup_basic_outcome_failure_exception_from_error(const S &ec, search_detail_adl )
- {
-
- return basic_outcome_failure_exception_from_error(ec);
- }
- }
- #if defined(_MSC_VER) && _MSC_VER <= 1923
-
- template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) { static_assert(sizeof(S) == 0, "No specialisation for these error and exception types available!"); }
- #else
- template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) = delete;
- #endif
- template <class exception_type> inline exception_type current_exception_or_fatal(std::exception_ptr e) { std::rethrow_exception(e); }
- template <> inline std::exception_ptr current_exception_or_fatal<std::exception_ptr>(std::exception_ptr e) { return e; }
- template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_failure_observers : public Base
- {
- public:
- using exception_type = P;
- using Base::Base;
- exception_type failure() const noexcept
- {
- #ifndef BOOST_NO_EXCEPTIONS
- try
- #endif
- {
- if(this->_state._status.have_exception())
- {
- return this->assume_exception();
- }
- if(this->_state._status.have_error())
- {
- return _delayed_lookup_basic_outcome_failure_exception_from_error(this->assume_error(), adl::search_detail_adl());
- }
- return exception_type();
- }
- #ifndef BOOST_NO_EXCEPTIONS
- catch(...)
- {
-
-
- return current_exception_or_fatal<exception_type>(std::current_exception());
- }
- #endif
- }
- };
- }
- BOOST_OUTCOME_V2_NAMESPACE_END
- #endif
|