File indexing completed on 2024-11-15 09:20:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
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 }
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 }
0051
0052 namespace policy
0053 {
0054 struct base;
0055 }
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;
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;
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
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;
0101 basic_result_storage(basic_result_storage &&) = default;
0102 basic_result_storage &operator=(const basic_result_storage &) = default;
0103 basic_result_storage &operator=(basic_result_storage &&) = default;
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 , 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 , 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 , 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 , 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 , 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 , 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 }
0185 BOOST_OUTCOME_V2_NAMESPACE_END
0186
0187 #endif