Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:20:28

0001 /* Storage for a very simple basic_result type
0002 (C) 2017-2023 Niall Douglas <http://www.nedproductions.biz/> (6 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_RESULT_STORAGE_HPP
0032 #define BOOST_OUTCOME_BASIC_RESULT_STORAGE_HPP
0033 
0034 #include "../success_failure.hpp"
0035 #include "../trait.hpp"
0036 #include "value_storage.hpp"
0037 
0038 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
0039 
0040 namespace detail
0041 {
0042   template <class R, class EC, class NoValuePolicy> class basic_result_storage;
0043 }  // namespace detail
0044 
0045 namespace hooks
0046 {
0047   template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept;
0048   template <class R, class S, class NoValuePolicy>
0049   constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept;
0050 }  // namespace hooks
0051 
0052 namespace policy
0053 {
0054   struct base;
0055 }  // namespace policy
0056 
0057 namespace detail
0058 {
0059   template <class R, class EC, class NoValuePolicy>  //
0060   class basic_result_storage
0061   {
0062     static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
0063     static_assert(trait::type_can_be_used_in_basic_result<EC>, "The type S cannot be used in a basic_result");
0064 
0065     friend struct policy::base;
0066     template <class T, class U, class V>  //
0067     friend class basic_result_storage;
0068     template <class T, class U, class V> friend class basic_result_final;
0069     template <class T, class U, class V>
0070     friend constexpr inline uint16_t hooks::spare_storage(const detail::basic_result_storage<T, U, V> *r) noexcept;  // NOLINT
0071     template <class T, class U, class V>
0072     friend constexpr inline void hooks::set_spare_storage(detail::basic_result_storage<T, U, V> *r, uint16_t v) noexcept;  // NOLINT
0073 
0074     struct disable_in_place_value_type
0075     {
0076     };
0077     struct disable_in_place_error_type
0078     {
0079     };
0080 
0081   protected:
0082     using _value_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_value_type, R>;
0083     using _error_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_error_type, EC>;
0084 
0085     using _state_type = value_storage_select_impl<_value_type, _error_type>;
0086 
0087 #ifdef BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE
0088     value_storage_trivial<_value_type, _error_type> _state;
0089 #else
0090     _state_type _state;
0091 #endif
0092 
0093   public:
0094     // Used by iostream support to access state
0095     _state_type &_iostreams_state() { return _state; }
0096     const _state_type &_iostreams_state() const { return _state; }
0097 
0098   protected:
0099     basic_result_storage() = default;
0100     basic_result_storage(const basic_result_storage &) = default;             // NOLINT
0101     basic_result_storage(basic_result_storage &&) = default;                  // NOLINT
0102     basic_result_storage &operator=(const basic_result_storage &) = default;  // NOLINT
0103     basic_result_storage &operator=(basic_result_storage &&) = default;       // NOLINT
0104     ~basic_result_storage() = default;
0105 
0106     template <class... Args>
0107     constexpr explicit basic_result_storage(in_place_type_t<_value_type> _,
0108                                             Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, Args...>)
0109         : _state{_, static_cast<Args &&>(args)...}
0110     {
0111     }
0112     template <class U, class... Args>
0113     constexpr basic_result_storage(in_place_type_t<_value_type> _, std::initializer_list<U> il,
0114                                    Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, std::initializer_list<U>, Args...>)
0115         : _state{_, il, static_cast<Args &&>(args)...}
0116     {
0117     }
0118     template <class... Args>
0119     constexpr explicit basic_result_storage(in_place_type_t<_error_type> _,
0120                                             Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, Args...>)
0121         : _state{_, static_cast<Args &&>(args)...}
0122     {
0123     }
0124     template <class U, class... Args>
0125     constexpr basic_result_storage(in_place_type_t<_error_type> _, std::initializer_list<U> il,
0126                                    Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, std::initializer_list<U>, Args...>)
0127         : _state{_, il, static_cast<Args &&>(args)...}
0128     {
0129     }
0130 
0131     struct compatible_conversion_tag
0132     {
0133     };
0134     template <class T, class U, class V>
0135     constexpr basic_result_storage(compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
0136     detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
0137         : _state(o._state)
0138     {
0139     }
0140     template <class T, class U, class V>
0141     constexpr basic_result_storage(compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
0142     detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
0143         : _state(static_cast<decltype(o._state) &&>(o._state))
0144     {
0145     }
0146 
0147     struct make_error_code_compatible_conversion_tag
0148     {
0149     };
0150     template <class T, class U, class V>
0151     constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
0152     detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
0153         : _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
0154                                                  _state_type(in_place_type<_error_type>, make_error_code(o._state._error)))
0155     {
0156     }
0157     template <class T, class U, class V>
0158     constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
0159     detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
0160         : _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
0161                                                  _state_type(in_place_type<_error_type>, make_error_code(static_cast<U &&>(o._state._error))))
0162     {
0163     }
0164 
0165     struct make_exception_ptr_compatible_conversion_tag
0166     {
0167     };
0168     template <class T, class U, class V>
0169     constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(
0170     detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
0171         : _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, o._state._value) :
0172                                                  _state_type(in_place_type<_error_type>, make_exception_ptr(o._state._error)))
0173     {
0174     }
0175     template <class T, class U, class V>
0176     constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(
0177     detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
0178         : _state(o._state._status.have_value() ? _state_type(in_place_type<_value_type>, static_cast<T &&>(o._state._value)) :
0179                                                  _state_type(in_place_type<_error_type>, make_exception_ptr(static_cast<U &&>(o._state._error))))
0180     {
0181     }
0182   };
0183 
0184 }  // namespace detail
0185 BOOST_OUTCOME_V2_NAMESPACE_END
0186 
0187 #endif