Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /* Traits for Outcome
0002 (C) 2018-2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
0003 File Created: March 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_TRAIT_STD_ERROR_CODE_HPP
0032 #define BOOST_OUTCOME_TRAIT_STD_ERROR_CODE_HPP
0033 
0034 #include "../config.hpp"
0035 
0036 #include <system_error>
0037 
0038 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
0039 
0040 namespace detail
0041 {
0042   // Customise _set_error_is_errno
0043   template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_code &error)
0044   {
0045     if(error.category() == std::generic_category()
0046 #ifndef _WIN32
0047        || error.category() == std::system_category()
0048 #endif
0049     )
0050     {
0051       state._status.set_have_error_is_errno(true);
0052     }
0053   }
0054   template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_condition &error)
0055   {
0056     if(error.category() == std::generic_category()
0057 #ifndef _WIN32
0058        || error.category() == std::system_category()
0059 #endif
0060     )
0061     {
0062       state._status.set_have_error_is_errno(true);
0063     }
0064   }
0065   template <class State> constexpr inline void _set_error_is_errno(State &state, const std::errc & /*unused*/) {
0066       state._status.set_have_error_is_errno(true);
0067    }
0068 
0069 }  // namespace detail
0070 
0071 namespace policy
0072 {
0073   namespace detail
0074   {
0075     /* Pass through `make_error_code` function for `std::error_code`.
0076      */
0077     inline std::error_code make_error_code(std::error_code v) { return v; }
0078 
0079     // Try ADL, if not use fall backs above
0080     template <class T> constexpr inline decltype(auto) error_code(T &&v) { return make_error_code(std::forward<T>(v)); }
0081 
0082     struct std_enum_overload_tag
0083     {
0084     };
0085   }  // namespace detail
0086 
0087   /*! AWAITING HUGO JSON CONVERSION TOOL 
0088 SIGNATURE NOT RECOGNISED
0089 */
0090   template <class T> constexpr inline decltype(auto) error_code(T &&v) { return detail::error_code(std::forward<T>(v)); }
0091 
0092   /*! AWAITING HUGO JSON CONVERSION TOOL 
0093 SIGNATURE NOT RECOGNISED
0094 */
0095   // inline void outcome_throw_as_system_error_with_payload(...) = delete;  // To use the error_code_throw_as_system_error policy with a custom Error type, you must define a outcome_throw_as_system_error_with_payload() free function to say how to handle the payload
0096   inline void outcome_throw_as_system_error_with_payload(const std::error_code &error) { BOOST_OUTCOME_THROW_EXCEPTION(std::system_error(error)); }  // NOLINT
0097   BOOST_OUTCOME_TEMPLATE(class Error)
0098   BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_error_code_enum<std::decay_t<Error>>::value || std::is_error_condition_enum<std::decay_t<Error>>::value))
0099   inline void outcome_throw_as_system_error_with_payload(Error &&error, detail::std_enum_overload_tag /*unused*/ = detail::std_enum_overload_tag()) { BOOST_OUTCOME_THROW_EXCEPTION(std::system_error(make_error_code(error))); }  // NOLINT
0100 }  // namespace policy
0101 
0102 namespace trait
0103 {
0104   namespace detail
0105   {
0106     template <> struct _is_error_code_available<std::error_code>
0107     {
0108       // Shortcut this for lower build impact
0109       static constexpr bool value = true;
0110       using type = std::error_code;
0111     };
0112   }  // namespace detail
0113 
0114   // std::error_code is an error type
0115   template <> struct is_error_type<std::error_code>
0116   {
0117     static constexpr bool value = true;
0118   };
0119   // For std::error_code, std::is_error_condition_enum<> is the trait we want.
0120   template <class Enum> struct is_error_type_enum<std::error_code, Enum>
0121   {
0122     static constexpr bool value = std::is_error_condition_enum<Enum>::value;
0123   };
0124 
0125 }  // namespace trait
0126 
0127 BOOST_OUTCOME_V2_NAMESPACE_END
0128 
0129 #endif