Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /* A very simple result type
0002 (C) 2018-2024 Niall Douglas <http://www.nedproductions.biz/> (11 commits)
0003 File Created: Apr 2018
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_EXPERIMENTAL_STATUS_RESULT_HPP
0032 #define BOOST_OUTCOME_EXPERIMENTAL_STATUS_RESULT_HPP
0033 
0034 #include "../basic_result.hpp"
0035 #include "../policy/fail_to_compile_observers.hpp"
0036 
0037 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_USE_STD_ADDRESSOF
0038 #if BOOST_OUTCOME_USE_STD_ADDRESSOF
0039 #define BOOST_OUTCOME_SYSTEM_ERROR2_USE_STD_ADDRESSOF 1
0040 #endif
0041 #endif
0042 
0043 #if __PCPP_ALWAYS_TRUE__
0044 #include "status-code/system_error2.hpp"
0045 #elif !BOOST_OUTCOME_USE_SYSTEM_STATUS_CODE && __has_include("status-code/system_error2.hpp")
0046 #include "status-code/system_error2.hpp"
0047 #else
0048 #include <status-code/system_error2.hpp>
0049 #endif
0050 
0051 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
0052 
0053 namespace trait
0054 {
0055   namespace detail
0056   {
0057     // Shortcut this for lower build impact. Used to tell outcome's converting constructors
0058     // that they can do E => EC or E => EP as necessary.
0059     template <class DomainType> struct _is_error_code_available<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
0060     {
0061       static constexpr bool value = true;
0062       using type = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>;
0063     };
0064     template <class DomainType> struct _is_error_code_available<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>
0065     {
0066       static constexpr bool value = true;
0067       using type = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>;
0068     };
0069   }    // namespace detail
0070 #if 0  // Do NOT enable weakened implicit construction for these types
0071   template <class DomainType> struct is_error_type<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
0072   {
0073     static constexpr bool value = true;
0074   };
0075   template <> struct is_error_type<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errc>
0076   {
0077     static constexpr bool value = true;
0078   };
0079   template <class DomainType, class Enum> struct is_error_type_enum<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>, Enum>
0080   {
0081     static constexpr bool value = boost::system::is_error_condition_enum<Enum>::value;
0082   };
0083 #endif
0084 
0085   template <class DomainType> struct is_move_bitcopying<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
0086   {
0087     static constexpr bool value = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::traits::is_move_bitcopying<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>::value;
0088   };
0089   template <class DomainType> struct is_move_bitcopying<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>
0090   {
0091     static constexpr bool value = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::traits::is_move_bitcopying<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>::value;
0092   };
0093 }  // namespace trait
0094 
0095 namespace detail
0096 {
0097   // Customise _set_error_is_errno
0098   template <class State> constexpr inline void _set_error_is_errno(State &state, const BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::generic_code & /*unused*/)
0099   {
0100     state._status.set_have_error_is_errno(true);
0101   }
0102 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_NOT_POSIX
0103   template <class State> constexpr inline void _set_error_is_errno(State &state, const BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::posix_code & /*unused*/)
0104   {
0105     state._status.set_have_error_is_errno(true);
0106   }
0107 #endif
0108   template <class State> constexpr inline void _set_error_is_errno(State &state, const BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errc & /*unused*/)
0109   {
0110     state._status.set_have_error_is_errno(true);
0111   }
0112 
0113 }  // namespace detail
0114 
0115 namespace experimental
0116 {
0117   using namespace BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE;
0118   using BOOST_OUTCOME_V2_NAMESPACE::failure;
0119   using BOOST_OUTCOME_V2_NAMESPACE::success;
0120 
0121   namespace policy
0122   {
0123     using namespace BOOST_OUTCOME_V2_NAMESPACE::policy;
0124     template <class T, class EC, class E> struct status_code_throw
0125     {
0126       static_assert(!std::is_same<T, T>::value,
0127                     "policy::status_code_throw not specialised for these types, did you use status_result<T, status_code<DomainType>, E>?");
0128     };
0129     template <class T, class DomainType> struct status_code_throw<T, status_code<DomainType>, void> : base
0130     {
0131       using _base = base;
0132       template <class Impl> static constexpr void wide_value_check(Impl &&self)
0133       {
0134         if(!base::_has_value(static_cast<Impl &&>(self)))
0135         {
0136           if(base::_has_error(static_cast<Impl &&>(self)))
0137           {
0138 #ifndef BOOST_NO_EXCEPTIONS
0139             base::_error(static_cast<Impl &&>(self)).throw_exception();
0140 #else
0141             BOOST_OUTCOME_THROW_EXCEPTION("wide value check failed");
0142 #endif
0143           }
0144         }
0145       }
0146       template <class Impl> static constexpr void wide_error_check(Impl &&self) { _base::narrow_error_check(static_cast<Impl &&>(self)); }
0147     };
0148     template <class T, class DomainType>
0149     struct status_code_throw<T, errored_status_code<DomainType>, void> : status_code_throw<T, status_code<DomainType>, void>
0150     {
0151       status_code_throw() = default;
0152       using status_code_throw<T, status_code<DomainType>, void>::status_code_throw;
0153     };
0154 
0155     template <class T, class EC>
0156     using default_status_result_policy = std::conditional_t<                            //
0157     std::is_void<EC>::value,                                                            //
0158     BOOST_OUTCOME_V2_NAMESPACE::policy::terminate,                                            //
0159     std::conditional_t<is_status_code<EC>::value || is_errored_status_code<EC>::value,  //
0160                        status_code_throw<T, EC, void>,                                  //
0161                        BOOST_OUTCOME_V2_NAMESPACE::policy::fail_to_compile_observers          //
0162                        >>;
0163   }  // namespace policy
0164 
0165   /*! AWAITING HUGO JSON CONVERSION TOOL
0166 SIGNATURE NOT RECOGNISED
0167 */
0168   template <class R, class S = erased_errored_status_code<typename system_code::value_type>,
0169             class NoValuePolicy = policy::default_status_result_policy<R, S>>  //
0170   using status_result = basic_result<R, S, NoValuePolicy>;
0171 
0172   /*! AWAITING HUGO JSON CONVERSION TOOL
0173 SIGNATURE NOT RECOGNISED
0174 */
0175   BOOST_OUTCOME_TEMPLATE(class R, class S, class NoValuePolicy)
0176   BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<R>::value && (is_status_code<S>::value || is_errored_status_code<S>::value)))
0177   inline basic_result<R, S, NoValuePolicy> clone(const basic_result<R, S, NoValuePolicy> &v)
0178   {
0179     if(v)
0180     {
0181       return success_type<R>(v.assume_value());
0182     }
0183     return failure_type<S>(v.assume_error().clone(), hooks::spare_storage(&v));
0184   }
0185 
0186   /*! AWAITING HUGO JSON CONVERSION TOOL
0187 SIGNATURE NOT RECOGNISED
0188 */
0189   BOOST_OUTCOME_TEMPLATE(class S, class NoValuePolicy)
0190   BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(is_status_code<S>::value || is_errored_status_code<S>::value))
0191   inline basic_result<void, S, NoValuePolicy> clone(const basic_result<void, S, NoValuePolicy> &v)
0192   {
0193     if(v)
0194     {
0195       return success_type<void>();
0196     }
0197     return failure_type<S>(v.assume_error().clone(), hooks::spare_storage(&v));
0198   }
0199 
0200 }  // namespace experimental
0201 
0202 BOOST_OUTCOME_V2_NAMESPACE_END
0203 
0204 #endif