Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-04 08:33:21

0001 /* Proposed SG14 status_code
0002 (C) 2018 - 2021 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
0003 File Created: Feb 2018
0004 
0005 
0006 Licensed under the Apache License, Version 2.0 (the "License");
0007 you may not use this file except in compliance with the License.
0008 You may obtain a copy of the License in the accompanying file
0009 Licence.txt or at
0010 
0011 http://www.apache.org/licenses/LICENSE-2.0
0012 
0013 Unless required by applicable law or agreed to in writing, software
0014 distributed under the License is distributed on an "AS IS" BASIS,
0015 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 See the License for the specific language governing permissions and
0017 limitations under the License.
0018 
0019 
0020 Distributed under the Boost Software License, Version 1.0.
0021 (See accompanying file Licence.txt or copy at
0022 http://www.boost.org/LICENSE_1_0.txt)
0023 */
0024 
0025 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_CONFIG_HPP
0026 #define BOOST_OUTCOME_SYSTEM_ERROR2_CONFIG_HPP
0027 
0028 // < 0.1 each
0029 #include <cassert>
0030 #include <cstddef>  // for size_t
0031 #include <cstdlib>  // for free
0032 
0033 // 0.22
0034 #include <type_traits>
0035 
0036 // 0.29
0037 #include <atomic>
0038 
0039 // 0.28 (0.15 of which is exception_ptr)
0040 #include <exception>  // for std::exception
0041 // <new> includes <exception>, <exception> includes <new>
0042 #include <new>
0043 
0044 // 0.01
0045 #include <initializer_list>
0046 
0047 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_HAVE_BIT_CAST
0048 #ifdef __has_include
0049 #if __has_include(<bit>) && (__cplusplus >= 202002L || _HAS_CXX20)
0050 #define BOOST_OUTCOME_SYSTEM_ERROR2_HAVE_BIT_CAST 1
0051 #endif
0052 #elif __cplusplus >= 202002L
0053 #define BOOST_OUTCOME_SYSTEM_ERROR2_HAVE_BIT_CAST 1
0054 #endif
0055 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_HAVE_BIT_CAST
0056 #define BOOST_OUTCOME_SYSTEM_ERROR2_HAVE_BIT_CAST 0
0057 #endif
0058 #endif
0059 #if BOOST_OUTCOME_SYSTEM_ERROR2_HAVE_BIT_CAST
0060 #include <bit>
0061 #if __cpp_lib_bit_cast < 201806L
0062 #undef BOOST_OUTCOME_SYSTEM_ERROR2_HAVE_BIT_CAST
0063 #define BOOST_OUTCOME_SYSTEM_ERROR2_HAVE_BIT_CAST 0
0064 #endif
0065 #endif
0066 
0067 #if BOOST_OUTCOME_SYSTEM_ERROR2_USE_STD_ADDRESSOF
0068 #include <memory>  // for std::addressof
0069 #define BOOST_OUTCOME_SYSTEM_ERROR2_ADDRESS_OF(...) std::addressof(__VA_ARGS__)
0070 #else
0071 #define BOOST_OUTCOME_SYSTEM_ERROR2_ADDRESS_OF(...) (&__VA_ARGS__)
0072 #endif
0073 
0074 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14
0075 #if defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE) || __cplusplus >= 201400 || _MSC_VER >= 1910 /* VS2017 */
0076 //! Defined to be `constexpr` when on C++ 14 or better compilers. Usually automatic, can be overriden.
0077 #define BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 constexpr
0078 #else
0079 #define BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14
0080 #endif
0081 #endif
0082 
0083 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20
0084 #if defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE) || __cplusplus >= 202000 || _HAS_CXX20
0085 //! Defined to be `constexpr` when on C++ 20 or better compilers. Usually automatic, can be overriden.
0086 #define BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 constexpr
0087 #else
0088 #define BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20
0089 #endif
0090 #endif
0091 
0092 
0093 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN
0094 #if defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE) || (_HAS_CXX17 && _MSC_VER >= 1911 /* VS2017.3 */)
0095 #define BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN [[noreturn]]
0096 #endif
0097 #endif
0098 #if !defined(BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN)
0099 #ifdef __has_cpp_attribute
0100 #if __has_cpp_attribute(noreturn)
0101 #define BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN [[noreturn]]
0102 #endif
0103 #endif
0104 #endif
0105 #if !defined(BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN)
0106 #if defined(_MSC_VER)
0107 #define BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN __declspec(noreturn)
0108 #elif defined(__GNUC__)
0109 #define BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN __attribute__((__noreturn__))
0110 #else
0111 #define BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN
0112 #endif
0113 #endif
0114 // GCCs before 7 don't grok [[noreturn]] virtual functions, and warn annoyingly
0115 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 7
0116 #undef BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN
0117 #define BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN
0118 #endif
0119 
0120 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD
0121 #if defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE) || (_HAS_CXX17 && _MSC_VER >= 1911 /* VS2017.3 */)
0122 #define BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD [[nodiscard]]
0123 #endif
0124 #endif
0125 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD
0126 #ifdef __has_cpp_attribute
0127 #if __has_cpp_attribute(nodiscard)
0128 #define BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD [[nodiscard]]
0129 #endif
0130 #elif defined(__clang__)
0131 #define BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD __attribute__((warn_unused_result))
0132 #elif defined(_MSC_VER)
0133 // _Must_inspect_result_ expands into this
0134 #define BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD                                                                                                                                \
0135   __declspec(                                                                                                                                                  \
0136   "SAL_name"                                                                                                                                                   \
0137   "("                                                                                                                                                          \
0138   "\"_Must_inspect_result_\""                                                                                                                                  \
0139   ","                                                                                                                                                          \
0140   "\"\""                                                                                                                                                       \
0141   ","                                                                                                                                                          \
0142   "\"2\""                                                                                                                                                      \
0143   ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end")
0144 #endif
0145 #endif
0146 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD
0147 #define BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD
0148 #endif
0149 
0150 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI
0151 #if defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE) || (__clang_major__ >= 7 && !defined(__APPLE__))
0152 //! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
0153 #define BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI [[clang::trivial_abi]]
0154 #else
0155 #define BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI
0156 #endif
0157 #endif
0158 
0159 #if defined(__cpp_concepts) && !defined(BOOST_OUTCOME_SYSTEM_ERROR2_DISABLE_CONCEPTS_SUPPORT)
0160 #define BOOST_OUTCOME_SYSTEM_ERROR2_GLUE(x, y) x y
0161 
0162 #define BOOST_OUTCOME_SYSTEM_ERROR2_RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, count, ...) count
0163 #define BOOST_OUTCOME_SYSTEM_ERROR2_EXPAND_ARGS(args) BOOST_OUTCOME_SYSTEM_ERROR2_RETURN_ARG_COUNT args
0164 #define BOOST_OUTCOME_SYSTEM_ERROR2_COUNT_ARGS_MAX8(...) BOOST_OUTCOME_SYSTEM_ERROR2_EXPAND_ARGS((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
0165 
0166 #define BOOST_OUTCOME_SYSTEM_ERROR2_OVERLOAD_MACRO2(name, count) name##count
0167 #define BOOST_OUTCOME_SYSTEM_ERROR2_OVERLOAD_MACRO1(name, count) BOOST_OUTCOME_SYSTEM_ERROR2_OVERLOAD_MACRO2(name, count)
0168 #define BOOST_OUTCOME_SYSTEM_ERROR2_OVERLOAD_MACRO(name, count) BOOST_OUTCOME_SYSTEM_ERROR2_OVERLOAD_MACRO1(name, count)
0169 
0170 #define BOOST_OUTCOME_SYSTEM_ERROR2_CALL_OVERLOAD(name, ...) BOOST_OUTCOME_SYSTEM_ERROR2_GLUE(BOOST_OUTCOME_SYSTEM_ERROR2_OVERLOAD_MACRO(name, BOOST_OUTCOME_SYSTEM_ERROR2_COUNT_ARGS_MAX8(__VA_ARGS__)), (__VA_ARGS__))
0171 
0172 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND8(a, b, c, d, e, f, g, h) a &&BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND7(b, c, d, e, f, g, h)
0173 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND7(a, b, c, d, e, f, g) a &&BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND6(b, c, d, e, f, g)
0174 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND6(a, b, c, d, e, f) a &&BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND5(b, c, d, e, f)
0175 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND5(a, b, c, d, e) a &&BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND4(b, c, d, e)
0176 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND4(a, b, c, d) a &&BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND3(b, c, d)
0177 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND3(a, b, c) a &&BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND2(b, c)
0178 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND2(a, b) a &&BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND1(b)
0179 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND1(a) a
0180 
0181 //! Expands into a && b && c && ...
0182 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(...) requires BOOST_OUTCOME_SYSTEM_ERROR2_CALL_OVERLOAD(BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES_EXPAND, __VA_ARGS__)
0183 
0184 #define BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(...) template <__VA_ARGS__>
0185 #define BOOST_OUTCOME_SYSTEM_ERROR2_TEXPR(...)                                                                                                                               \
0186   requires { (__VA_ARGS__); }
0187 #define BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(...) (__VA_ARGS__)
0188 #if !defined(_MSC_VER) || _MSC_FULL_VER >= 192400000  // VS 2019 16.3 is broken here
0189 #define BOOST_OUTCOME_SYSTEM_ERROR2_REQUIRES(...) requires(__VA_ARGS__)
0190 #else
0191 #define BOOST_OUTCOME_SYSTEM_ERROR2_REQUIRES(...)
0192 #endif
0193 #else
0194 #define BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(...) template <__VA_ARGS__
0195 #define BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(...) , __VA_ARGS__ >
0196 #define BOOST_OUTCOME_SYSTEM_ERROR2_TEXPR(...) typename = decltype(__VA_ARGS__)
0197 #ifdef _MSC_VER
0198 // MSVC gives an error if every specialisation of a template is always ill-formed, so
0199 // the more powerful SFINAE form below causes pukeage :(
0200 #define BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(...) typename = typename std::enable_if<(__VA_ARGS__)>::type
0201 #else
0202 #define BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(...) typename std::enable_if<(__VA_ARGS__), bool>::type = true
0203 #endif
0204 #define BOOST_OUTCOME_SYSTEM_ERROR2_REQUIRES(...)
0205 #endif
0206 
0207 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE
0208 //! The system_error2 namespace name.
0209 #define BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE system_error2
0210 //! Begins the system_error2 namespace.
0211 #define BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN                                                                                                                          \
0212   namespace system_error2                                                                                                                                      \
0213   {
0214 //! Ends the system_error2 namespace.
0215 #define BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END }
0216 #endif
0217 
0218 //! Namespace for the library
0219 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
0220 
0221 //! Namespace for user specialised traits
0222 namespace traits
0223 {
0224   /*! Specialise to true if you guarantee that a type is move bitcopying (i.e.
0225   its move constructor equals copying bits from old to new, old is left in a
0226   default constructed state, and calling the destructor on a default constructed
0227   instance is trivial). All trivially copyable types are move bitcopying by
0228   definition, and that is the unspecialised implementation.
0229   */
0230   template <class T> struct is_move_bitcopying
0231   {
0232     static constexpr bool value = std::is_trivially_copyable<T>::value;
0233   };
0234 }  // namespace traits
0235 
0236 namespace detail
0237 {
0238 #if __cplusplus >= 201400 || _MSC_VER >= 1910 /* VS2017 */
0239   inline constexpr size_t cstrlen(const char *str)
0240   {
0241     const char *end = nullptr;
0242     for(end = str; *end != 0; ++end)  // NOLINT
0243       ;
0244     return end - str;
0245   }
0246 #else
0247   inline constexpr size_t cstrlen_(const char *str, size_t acc) { return (str[0] == 0) ? acc : cstrlen_(str + 1, acc + 1); }
0248   inline constexpr size_t cstrlen(const char *str) { return cstrlen_(str, 0); }
0249 #endif
0250 
0251 #if(__cplusplus >= 202002L || _MSVC_LANG >= 202002L) && __cpp_lib_remove_cvref >= 201711L
0252 
0253   template <class T> using remove_cvref = std::remove_cvref<T>;
0254 
0255 #else
0256 
0257   template <class T> struct remove_cvref
0258   {
0259     using type = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
0260   };
0261 
0262 #endif
0263 
0264   /* A partially compliant implementation of C++20's std::bit_cast function contributed
0265   by Jesse Towner.
0266 
0267   Our bit_cast is only guaranteed to be constexpr when both the input and output
0268   arguments are either integrals or enums. However, this covers most use cases
0269   since the vast majority of status_codes have an underlying type that is either
0270   an integral or enum. We still attempt a constexpr union-based type pun for non-array
0271   input types, which some compilers accept. For array inputs, we fall back to
0272   non-constexpr memmove.
0273   */
0274 
0275   template <class T> using is_integral_or_enum = std::integral_constant<bool, std::is_integral<T>::value || std::is_enum<T>::value>;
0276 
0277   template <class To, class From> using is_static_castable = std::integral_constant<bool, is_integral_or_enum<To>::value && is_integral_or_enum<From>::value>;
0278 
0279   template <class To, class From>
0280   using is_union_castable = std::integral_constant<bool, !is_static_castable<To, From>::value && !std::is_array<To>::value && !std::is_array<From>::value>;
0281 
0282   template <class To, class From>
0283   using is_bit_castable =
0284   std::integral_constant<bool, sizeof(To) == sizeof(From) && traits::is_move_bitcopying<To>::value && traits::is_move_bitcopying<From>::value>;
0285 
0286   template <class To, class From> union bit_cast_union
0287   {
0288     From source;
0289     To target;
0290   };
0291 
0292 #if BOOST_OUTCOME_SYSTEM_ERROR2_HAVE_BIT_CAST
0293   using std::bit_cast;  // available for all trivially copyable types
0294 
0295   // For move bit copying types
0296   template <class To, class From>
0297   requires(is_bit_castable<To, From>::value             //
0298            &&is_union_castable<To, From>::value         //
0299            && (!std::is_trivially_copyable_v<From>      //
0300                || !std::is_trivially_copyable_v<To>) )  //
0301   constexpr To bit_cast(const From &from) noexcept
0302   {
0303     return bit_cast_union<To, From>{from}.target;
0304   }
0305   template <class To, class From>
0306   requires(is_bit_castable<To, From>::value             //
0307            && !is_union_castable<To, From>::value       //
0308            && (!std::is_trivially_copyable_v<From>      //
0309                || !std::is_trivially_copyable_v<To>) )  //
0310   To bit_cast(const From &from)
0311   noexcept
0312   {
0313     bit_cast_union<To, From> ret;
0314     memmove(&ret.source, &from, sizeof(ret.source));
0315     return ret.target;
0316   }
0317 #else
0318   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From, int = 5)
0319   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_bit_castable<To, From>::value       //
0320                                               &&is_static_castable<To, From>::value  //
0321                                               && !is_union_castable<To, From>::value))
0322   constexpr To bit_cast(const From &from) noexcept { return static_cast<To>(from); }
0323 
0324 #if defined(__GNUC__) && !defined(__clang__)
0325 #pragma GCC diagnostic push
0326 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
0327 #endif
0328   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From, long = 5)
0329   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_bit_castable<To, From>::value         //
0330                                               && !is_static_castable<To, From>::value  //
0331                                               && is_union_castable<To, From>::value))
0332   constexpr To bit_cast(const From &from) noexcept { return bit_cast_union<To, From>{from}.target; }
0333 #if defined(__GNUC__) && !defined(__clang__)
0334 #pragma GCC diagnostic pop
0335 #endif
0336 
0337   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From, short = 5)
0338   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_bit_castable<To, From>::value         //
0339                                               && !is_static_castable<To, From>::value  //
0340                                               && !is_union_castable<To, From>::value))
0341   To bit_cast(const From &from) noexcept
0342   {
0343     bit_cast_union<To, From> ret;
0344     memmove(&ret.source, &from, sizeof(ret.source));
0345     return ret.target;
0346   }
0347 #endif
0348 
0349   /* erasure_cast performs a bit_cast with additional rules to handle types
0350   of differing sizes. For integral & enum types, it may perform a narrowing
0351   or widing conversion with static_cast if necessary, before doing the final
0352   conversion with bit_cast. When casting to or from non-integral, non-enum
0353   types it may insert the value into another object with extra padding bytes
0354   to satisfy bit_cast's preconditions that both types have the same size. */
0355 
0356   template <class To, class From>
0357   using is_erasure_castable = std::integral_constant<bool, traits::is_move_bitcopying<To>::value && traits::is_move_bitcopying<From>::value>;
0358 
0359   template <class T, bool = std::is_enum<T>::value> struct identity_or_underlying_type
0360   {
0361     using type = T;
0362   };
0363   template <class T> struct identity_or_underlying_type<T, true>
0364   {
0365     using type = typename std::underlying_type<T>::type;
0366   };
0367 
0368   template <class OfSize, class OfSign>
0369   using erasure_integer_type = typename std::conditional<std::is_signed<typename identity_or_underlying_type<OfSign>::type>::value,
0370                                                          typename std::make_signed<typename identity_or_underlying_type<OfSize>::type>::type,
0371                                                          typename std::make_unsigned<typename identity_or_underlying_type<OfSize>::type>::type>::type;
0372 
0373   template <class ErasedType, std::size_t N> struct padded_erasure_object
0374   {
0375     static_assert(traits::is_move_bitcopying<ErasedType>::value, "ErasedType must be TriviallyCopyable or MoveBitcopying");
0376     static_assert(alignof(ErasedType) <= sizeof(ErasedType), "ErasedType must not be over-aligned");
0377     ErasedType value;
0378     char padding[N];
0379     constexpr explicit padded_erasure_object(const ErasedType &v) noexcept
0380         : value(v)
0381         , padding{}
0382     {
0383     }
0384   };
0385 
0386   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From)
0387   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && (sizeof(To) == sizeof(From))))
0388   constexpr To erasure_cast(const From &from) noexcept { return bit_cast<To>(from); }
0389 
0390 #if defined(_WIN32) || defined(__APPLE__) || __LITTLE_ENDIAN__ || (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN)
0391   // We can avoid the type pun on little endian architectures which can aid optimisation
0392   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From, long = 5)
0393   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value &&is_static_castable<To, From>::value && (sizeof(To) < sizeof(From))))
0394   constexpr To erasure_cast(const From &from) noexcept { return static_cast<To>(bit_cast<erasure_integer_type<From, To>>(from)); }
0395 
0396   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From, int = 5)
0397   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value &&is_static_castable<To, From>::value && (sizeof(To) > sizeof(From))))
0398   constexpr To erasure_cast(const From &from) noexcept { return bit_cast<To>(static_cast<erasure_integer_type<To, From>>(from)); }
0399 
0400   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From, short = 5)
0401   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && !is_static_castable<To, From>::value && (sizeof(To) < sizeof(From))))
0402   constexpr To erasure_cast(const From &from) noexcept { return bit_cast<padded_erasure_object<To, sizeof(From) - sizeof(To)>>(from).value; }
0403 
0404   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From, char = 5)
0405   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && !is_static_castable<To, From>::value && (sizeof(To) > sizeof(From))))
0406   constexpr To erasure_cast(const From &from) noexcept { return bit_cast<To>(padded_erasure_object<From, sizeof(To) - sizeof(From)>{from}); }
0407 #else
0408   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From, short = 5)
0409   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && (sizeof(To) < sizeof(From))))
0410   constexpr To erasure_cast(const From &from) noexcept { return bit_cast<padded_erasure_object<To, sizeof(From) - sizeof(To)>>(from).value; }
0411 
0412   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class To, class From, char = 5)
0413   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_erasure_castable<To, From>::value && (sizeof(To) > sizeof(From))))
0414   constexpr To erasure_cast(const From &from) noexcept { return bit_cast<To>(padded_erasure_object<From, sizeof(To) - sizeof(From)>{from}); }
0415 #endif
0416 }  // namespace detail
0417 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
0418 
0419 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_FATAL
0420 #ifdef BOOST_OUTCOME_SYSTEM_ERROR2_NOT_POSIX
0421 #error If BOOST_OUTCOME_SYSTEM_ERROR2_NOT_POSIX is defined, you must define your own BOOST_OUTCOME_SYSTEM_ERROR2_FATAL implementation!
0422 #endif
0423 #include <cstdlib>  // for abort
0424 #ifdef __APPLE__
0425 #include <unistd.h>  // for write
0426 #endif
0427 
0428 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
0429 namespace detail
0430 {
0431   namespace avoid_stdio_include
0432   {
0433 #if !defined(__APPLE__) && !defined(_MSC_VER)
0434     extern "C" ptrdiff_t write(int, const void *, size_t);
0435 #elif defined(_MSC_VER)
0436     extern ptrdiff_t write(int, const void *, size_t);
0437 #if(defined(__x86_64__) || defined(_M_X64)) || (defined(__aarch64__) || defined(_M_ARM64)) || (defined(__arm__) || defined(_M_ARM))
0438 #pragma comment(linker, "/alternatename:?write@avoid_stdio_include@detail@system_error2@@YA_JHPEBX_K@Z=write")
0439 #elif defined(__x86__) || defined(_M_IX86) || defined(__i386__)
0440 #pragma comment(linker, "/alternatename:?write@avoid_stdio_include@detail@system_error2@@YAHHPBXI@Z=_write")
0441 #else
0442 #error Unknown architecture
0443 #endif
0444 #endif
0445   }  // namespace avoid_stdio_include
0446   inline void do_fatal_exit(const char *msg)
0447   {
0448     using namespace avoid_stdio_include;
0449     write(2 /*stderr*/, msg, cstrlen(msg));
0450     write(2 /*stderr*/, "\n", 1);
0451     abort();
0452   }
0453 }  // namespace detail
0454 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
0455 //! Prints msg to stderr, and calls `std::terminate()`. Can be overriden via predefinition.
0456 #define BOOST_OUTCOME_SYSTEM_ERROR2_FATAL(msg) ::BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::detail::do_fatal_exit(msg)
0457 #endif
0458 
0459 #endif