Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:59:08

0001 /* Failure observers for outcome type
0002 (C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
0003 File Created: Oct 2017
0004 
0005 
0006 Boost Software License - Version 1.0 - August 17th, 2003
0007 
0008 Permission is hereby granted, free of charge, to any person or organization
0009 obtaining a copy of the software and accompanying documentation covered by
0010 this license (the "Software") to use, reproduce, display, distribute,
0011 execute, and transmit the Software, and to prepare derivative works of the
0012 Software, and to permit third-parties to whom the Software is furnished to
0013 do so, all subject to the following:
0014 
0015 The copyright notices in the Software and this entire statement, including
0016 the above license grant, this restriction and the following disclaimer,
0017 must be included in all copies of the Software, in whole or in part, and
0018 all derivative works of the Software, unless such copies or derivative
0019 works are solely in the form of machine-executable object code generated by
0020 a source language processor.
0021 
0022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0023 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0024 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
0025 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
0026 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
0027 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0028 DEALINGS IN THE SOFTWARE.
0029 */
0030 
0031 #ifndef BOOST_OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
0032 #define BOOST_OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
0033 
0034 #include "basic_result_storage.hpp"
0035 
0036 #include <exception>
0037 
0038 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
0039 
0040 namespace detail
0041 {
0042   namespace adl
0043   {
0044     struct search_detail_adl
0045     {
0046     };
0047     // Do NOT use template requirements here!
0048     template <class S, typename = decltype(basic_outcome_failure_exception_from_error(std::declval<S>()))>
0049     inline auto _delayed_lookup_basic_outcome_failure_exception_from_error(const S &ec, search_detail_adl /*unused*/)
0050     {
0051       // ADL discovered
0052       return basic_outcome_failure_exception_from_error(ec);
0053     }
0054   }                                        // namespace adl
0055 #if defined(_MSC_VER) && _MSC_VER <= 1923  // VS2019
0056   // VS2017 and VS2019 with /permissive- chokes on the correct form due to over eager early instantiation.
0057   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!"); }
0058 #else
0059   template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) = delete;  // NOLINT No specialisation for these error and exception types available!
0060 #endif
0061 
0062   template <class exception_type> inline exception_type current_exception_or_fatal(std::exception_ptr e) { std::rethrow_exception(e); }
0063   template <> inline std::exception_ptr current_exception_or_fatal<std::exception_ptr>(std::exception_ptr e) { return e; }
0064 
0065   template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_failure_observers : public Base
0066   {
0067   public:
0068     using exception_type = P;
0069     using Base::Base;
0070 
0071     exception_type failure() const noexcept
0072     {
0073 #ifndef BOOST_NO_EXCEPTIONS
0074       try
0075 #endif
0076       {
0077         if(this->_state._status.have_exception())
0078         {
0079           return this->assume_exception();
0080         }
0081         if(this->_state._status.have_error())
0082         {
0083           return _delayed_lookup_basic_outcome_failure_exception_from_error(this->assume_error(), adl::search_detail_adl());
0084         }
0085         return exception_type();
0086       }
0087 #ifndef BOOST_NO_EXCEPTIONS
0088       catch(...)
0089       {
0090         // Return the failure if exception_type is std::exception_ptr,
0091         // otherwise terminate same as throwing an exception inside noexcept
0092         return current_exception_or_fatal<exception_type>(std::current_exception());
0093       }
0094 #endif
0095     }
0096   };
0097 
0098 }  // namespace detail
0099 
0100 BOOST_OUTCOME_V2_NAMESPACE_END
0101 
0102 #endif