26 template<
typename Expected,
typename From,
typename To>
31template<
typename T,
typename E>
53 internal_construct_from_expected(
other);
60 internal_construct_from_expected(util::move(
other));
63 template<
typename U,
typename G>
68 internal_construct_from_expected(
other);
71 template<
typename U,
typename G>
76 internal_construct_from_expected(util::move(
other));
79 template<
typename U = T>
95 template<
typename... Args>
100 template<
typename U,
typename... Args>
105 template<
typename... Args>
110 template<
typename U,
typename... Args>
125 return internal_assign_from_expected(
other);
130 return internal_assign_from_expected(util::move(
other));
133 template<
typename U = T>
136 return internal_assign_from_value(util::forward<U>(
value));
142 return internal_assign_from_unexpected(
error);
148 return internal_assign_from_unexpected(util::move(
error));
156 constexpr auto operator*() && -> T&& {
return util::move(*this).value(); }
157 constexpr auto operator*() const&& -> T const&& {
return util::move(*this).value(); }
159 constexpr explicit operator bool()
const {
return has_value(); }
160 constexpr auto has_value() const ->
bool {
return !m_has_error; }
166 constexpr auto value() const& -> T const& {
166 constexpr auto value() const& -> T const& {
…}
172 return util::move(
m_value).value();
174 constexpr auto value() const&& -> T const&& {
176 return util::move(
m_value).value();
174 constexpr auto value() const&& -> T const&& {
…}
183 constexpr auto error() const& -> E const& {
183 constexpr auto error() const& -> E const& {
…}
189 return util::move(
m_error).value();
191 constexpr auto error() const&& -> E const&& {
193 return util::move(
m_error).value();
191 constexpr auto error() const&& -> E const&& {
…}
196 template<concepts::ConvertibleTo<T> U>
198 constexpr auto value_or(U&& default_value)
const& -> T {
199 return has_value() ? **this :
static_cast<T
>(util::forward<U>(default_value));
198 constexpr auto value_or(U&& default_value)
const& -> T {
…}
202 template<concepts::ConvertibleTo<T> U>
204 constexpr auto value_or(U&& default_value) && -> T {
205 return has_value() ? *util::move(*
this) :
static_cast<T
>(util::forward<U>(default_value));
209 requires(
concepts::CopyConstructible<T>)
220 template<
typename... Args>
222 constexpr auto emplace(Args&&... args) -> T& {
223 return internal_emplace(util::forward<Args>(args)...);
226 template<
typename U,
typename... Args>
228 constexpr auto emplace(std::initializer_list<U> list, Args&&... args) -> T& {
229 return internal_emplace(list, util::forward<Args>(args)...);
228 constexpr auto emplace(std::initializer_list<U> list, Args&&... args) -> T& {
…}
239 template<
typename U,
typename G>
242 template<concepts::EqualityComparableWith<T> U, concepts::EqualityComparableWith<E> G>
244 if (a.has_value() != b.has_value()) {
247 if (a.has_value() == b.has_value()) {
248 return a.value() == b.value();
250 return a.error() == b.error();
255 constexpr friend auto operator==(
Expected const& a, U
const& b) ->
bool {
256 return a.has_value() && a.value() == b;
255 constexpr friend auto operator==(
Expected const& a, U
const& b) ->
bool {
…}
259 template<concepts::EqualityComparableWith<E> G>
261 return !a.has_value() && a.error() == b.error();
264 template<concepts::RemoveCVRefSameAs<Expected> Self,
typename F,
265 typename U = meta::UnwrapRefDecay<meta::InvokeResult<F, meta::Like<Self, T>>>>
279 template<concepts::RemoveCVRefSameAs<Expected> Self,
typename F,
280 typename R = meta::InvokeResult<F, meta::Like<Self, T>>>
289 template<concepts::RemoveCVRefSameAs<Expected> Self,
typename F,
290 typename R = meta::InvokeResult<F, meta::Like<Self, E>>>
299 template<concepts::RemoveCVRefSameAs<Expected> Self,
typename F,
300 typename G = meta::UnwrapRefDecay<meta::InvokeResult<F, meta::Like<Self, E>>>>
316 constexpr void internal_construct_from_expected(U&& other) {
317 auto other_has_value = other.has_value();
318 if (other_has_value) {
323 this->m_has_error = !other_has_value;
326 constexpr void internal_reset() {
335 constexpr auto internal_assign_from_expected(U&& other) ->
Expected& {
336 if (this->has_value() && other.has_value()) {
337 this->m_value = util::forward<U>(other).value();
338 }
else if (this->has_value() && !other.has_value()) {
341 }
else if (!this->has_value() && other.has_value()) {
345 this->m_error = util::forward<U>(other).error();
347 this->m_has_error = !other.has_value();
352 constexpr auto internal_assign_from_value(U&& value) ->
Expected& {
353 if (this->has_value()) {
354 this->m_value = util::forward<U>(value);
359 this->m_has_error =
false;
364 constexpr auto internal_assign_from_unexpected(U&& unexpected) ->
Expected& {
365 if (this->has_value()) {
369 this->m_error = util::forward<U>(unexpected).error();
371 this->m_has_error =
true;
375 template<
typename... Args>
376 constexpr auto internal_emplace(Args&&... args) ->
T& {
377 if (this->has_value()) {
378 m_value.emplace(util::forward<Args>(args)...);
383 this->m_has_error =
false;
387 template<
typename U,
typename... Args>
388 constexpr auto internal_emplace(std::initializer_list<U> list, Args&&... args) ->
T& {
389 if (this->has_value()) {
390 m_value.emplace(list, util::forward<Args>(args)...);
395 this->m_has_error =
false;
399 bool m_has_error {
false };
#define DI_ASSERT(...)
Definition assert_bool.h:7
Definition rebindable_box.h:42
Definition expected_forward_declaration.h:8
E Error
Definition expected.h:36
constexpr friend auto tag_invoke(types::Tag< function::monad::fmap >, Self &&self, F &&function) -> Expected< U, E >
Definition expected.h:267
constexpr auto __try_move_out() &&-> T &&
Definition expected.h:236
constexpr auto has_value() const -> bool
Definition expected.h:160
constexpr auto value() &-> T &
Definition expected.h:162
constexpr G const & other
Definition expected.h:67
constexpr auto value_or(U &&default_value) const &-> T
Definition expected.h:198
constexpr auto operator*() &-> T &
Definition expected.h:154
constexpr Expected(types::InPlace, std::initializer_list< U > list, Args &&... args)
Definition expected.h:102
friend class Expected
Definition expected.h:240
constexpr auto optional_value() &&-> Optional< T > requires(concepts::MoveConstructible< T >)
Definition expected.h:214
constexpr friend auto tag_invoke(types::Tag< function::monad::fail >, Self &&self, F &&function) -> R
Definition expected.h:292
constexpr auto value_or(U &&default_value) &&-> T
Definition expected.h:204
constexpr auto emplace(Args &&... args) -> T &
Definition expected.h:222
constexpr auto operator*() &&-> T &&
Definition expected.h:156
constexpr auto value() const &&-> T const &&
Definition expected.h:174
constexpr auto operator*() const &-> T const &
Definition expected.h:155
constexpr Expected(types::InPlace, Args &&... args)
Definition expected.h:97
constexpr auto value() const &-> T const &
Definition expected.h:166
constexpr friend auto operator==(Expected const &a, Expected< U, G > const &b) -> bool
Definition expected.h:243
constexpr auto optional_value() const &-> Optional< T > requires(concepts::CopyConstructible< T >)
Definition expected.h:208
constexpr auto error() &&-> E &&
Definition expected.h:187
constexpr friend auto operator==(Expected const &a, Unexpected< G > const &b) -> bool
Definition expected.h:260
constexpr auto error() const &-> E const &
Definition expected.h:183
constexpr ~Expected()=default
constexpr Expected(Expected &&)=default
T Value
Definition expected.h:35
constexpr auto operator=(Expected const &other) -> Expected &requires(concepts::CopyConstructible< T > &&concepts::CopyConstructible< E >)
Definition expected.h:123
constexpr friend auto tag_invoke(types::Tag< function::monad::fmap_right >, Self &&self, F &&function) -> Expected< T, G >
Definition expected.h:301
constexpr auto value() &&-> T &&
Definition expected.h:170
constexpr Expected(Expected &&other)
Definition expected.h:56
util::RebindableBox< T > m_value
Definition expected.h:401
constexpr auto __try_did_succeed() &&-> Expected
Definition expected.h:235
constexpr auto error() const &&-> E const &&
Definition expected.h:191
constexpr auto emplace(std::initializer_list< U > list, Args &&... args) -> T &
Definition expected.h:228
constexpr Expected(Expected const &)=default
constexpr Expected(types::Unexpect, Args &&... args)
Definition expected.h:107
constexpr Expected(Expected const &)=delete
constexpr auto operator=(Expected &&other) -> Expected &requires(concepts::MoveConstructible< T > &&concepts::MoveConstructible< E >)
Definition expected.h:128
constexpr Expected(Expected const &other)
Definition expected.h:49
constexpr auto operator*() const &&-> T const &&
Definition expected.h:157
constexpr Expected()
Definition expected.h:38
constexpr ~Expected()
Definition expected.h:117
util::RebindableBox< E > m_error
Definition expected.h:402
constexpr auto __try_did_fail() &&-> Unexpected< E >
Definition expected.h:232
constexpr auto operator->()
Definition expected.h:151
constexpr Expected(types::Unexpect, std::initializer_list< U > list, Args &&... args)
Definition expected.h:112
constexpr friend auto tag_invoke(types::Tag< function::monad::bind >, Self &&self, F &&function) -> R
Definition expected.h:282
constexpr auto error() &-> E &
Definition expected.h:179
constexpr auto operator->() const
Definition expected.h:152
Definition optional_forward_declaration.h:5
Definition unexpected.h:14
Definition operations.h:11
Definition operations.h:99
Definition operations.h:34
Definition operations.h:24
Definition operations.h:43
Definition expected_can_convert_constructor.h:9
Definition any_storable.h:9
constexpr auto invoke
Definition invoke.h:100
constexpr auto value
Definition value.h:34
constexpr auto in_place
Definition in_place.h:8
di::meta::Decay< decltype(T)> Tag
Definition tag_invoke.h:28
constexpr auto unexpect
Definition unexpect.h:8
constexpr auto destroy_at
Definition destroy_at.h:24
constexpr auto construct_at
Definition construct_at.h:27
Definition erasure_cast.h:7
constexpr auto nullopt
Definition nullopt.h:15
Expected(T &&) -> Expected< meta::UnwrapRefDecay< T >, void >
constexpr auto in_place
Definition in_place.h:8