26 template<
typename Expected,
typename From,
typename To>
27 concept ConvertibleToWorkaround =
28 !concepts::SameAs<Expected, meta::RemoveCVRef<From>> && concepts::ConvertibleTo<From, To>;
31template<
typename T,
typename E>
32requires(!concepts::LanguageVoid<T> && !concepts::LanguageVoid<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>
82 constexpr explicit(!detail::ConvertibleToWorkaround<Expected, U, T>)
Expected(U&&
value)
95 template<
typename... Args>
100 template<
typename U,
typename... Args>
105 template<
typename... Args>
110 template<
typename U,
typename... Args>
126 return internal_assign_from_expected(
other);
132 return internal_assign_from_expected(util::move(
other));
135 template<
typename U = T>
138 return internal_assign_from_value(util::forward<U>(
value));
144 return internal_assign_from_unexpected(
error);
150 return internal_assign_from_unexpected(util::move(
error));
158 constexpr auto operator*() && -> T&& {
return util::move(*this).value(); }
159 constexpr auto operator*() const&& -> T const&& {
return util::move(*this).value(); }
161 constexpr explicit operator bool()
const {
return has_value(); }
162 constexpr auto has_value() const ->
bool {
return !m_has_error; }
168 constexpr auto value() const& -> T const& {
174 return util::move(
m_value).value();
176 constexpr auto value() const&& -> T const&& {
178 return util::move(
m_value).value();
185 constexpr auto error() const& -> E const& {
191 return util::move(
m_error).value();
193 constexpr auto error() const&& -> E const&& {
195 return util::move(
m_error).value();
198 template<concepts::ConvertibleTo<T> U>
200 constexpr auto value_or(U&& default_value)
const& -> T {
201 return has_value() ? **this :
static_cast<T
>(util::forward<U>(default_value));
204 template<concepts::ConvertibleTo<T> U>
206 constexpr auto value_or(U&& default_value) && -> T {
207 return has_value() ? *util::move(*
this) :
static_cast<T
>(util::forward<U>(default_value));
211 requires(
concepts::CopyConstructible<T>)
222 template<
typename... Args>
224 constexpr auto emplace(Args&&... args) -> T& {
225 return internal_emplace(util::forward<Args>(args)...);
228 template<
typename U,
typename... Args>
230 constexpr auto emplace(std::initializer_list<U> list, Args&&... args) -> T& {
231 return internal_emplace(list, util::forward<Args>(args)...);
241 template<
typename U,
typename G>
244 template<concepts::EqualityComparableWith<T> U, concepts::EqualityComparableWith<E> G>
246 if (a.has_value() != b.has_value()) {
249 if (a.has_value() == b.has_value()) {
250 return a.value() == b.value();
252 return a.error() == b.error();
257 constexpr friend auto operator==(
Expected const& a, U
const& b) ->
bool {
258 return a.has_value() && a.value() == b;
261 template<concepts::EqualityComparableWith<E> G>
263 return !a.has_value() && a.error() == b.error();
266 template<concepts::RemoveCVRefSameAs<Expected> Self,
typename F,
267 typename U = meta::UnwrapRefDecay<meta::InvokeResult<F, meta::Like<Self, T>>>>
281 template<concepts::RemoveCVRefSameAs<Expected> Self,
typename F,
282 typename R = meta::InvokeResult<F, meta::Like<Self, T>>>
291 template<concepts::RemoveCVRefSameAs<Expected> Self,
typename F,
292 typename R = meta::InvokeResult<F, meta::Like<Self, E>>>
301 template<concepts::RemoveCVRefSameAs<Expected> Self,
typename F,
302 typename G = meta::UnwrapRefDecay<meta::InvokeResult<F, meta::Like<Self, E>>>>
318 constexpr void internal_construct_from_expected(U&& other) {
319 auto other_has_value = other.has_value();
320 if (other_has_value) {
325 this->m_has_error = !other_has_value;
328 constexpr void internal_reset() {
337 constexpr auto internal_assign_from_expected(U&& other) ->
Expected& {
338 if (this->has_value() && other.has_value()) {
339 this->m_value = util::forward<U>(other).value();
340 }
else if (this->has_value() && !other.has_value()) {
343 }
else if (!this->has_value() && other.has_value()) {
347 this->m_error = util::forward<U>(other).error();
349 this->m_has_error = !other.has_value();
354 constexpr auto internal_assign_from_value(U&& value) ->
Expected& {
355 if (this->has_value()) {
356 this->m_value = util::forward<U>(value);
361 this->m_has_error =
false;
366 constexpr auto internal_assign_from_unexpected(U&& unexpected) ->
Expected& {
367 if (this->has_value()) {
371 this->m_error = util::forward<U>(unexpected).error();
373 this->m_has_error =
true;
377 template<
typename... Args>
378 constexpr auto internal_emplace(Args&&... args) -> T& {
379 if (this->has_value()) {
380 m_value.emplace(util::forward<Args>(args)...);
385 this->m_has_error =
false;
389 template<
typename U,
typename... Args>
390 constexpr auto internal_emplace(std::initializer_list<U> list, Args&&... args) -> T& {
391 if (this->has_value()) {
392 m_value.emplace(list, util::forward<Args>(args)...);
397 this->m_has_error =
false;
401 bool m_has_error {
false };
#define DI_ASSERT(...)
Definition assert_bool.h:7
Definition rebindable_box.h:42
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:269
constexpr auto __try_move_out() &&-> T &&
Definition expected.h:238
constexpr auto has_value() const -> bool
Definition expected.h:162
constexpr auto value() &-> T &
Definition expected.h:164
constexpr G const & other
Definition expected.h:67
constexpr auto value_or(U &&default_value) const &-> T
Definition expected.h:200
constexpr auto operator*() &-> T &
Definition expected.h:156
constexpr Expected(types::InPlace, std::initializer_list< U > list, Args &&... args)
Definition expected.h:102
friend class Expected
Definition expected.h:242
constexpr auto optional_value() &&-> Optional< T > requires(concepts::MoveConstructible< T >)
Definition expected.h:216
constexpr friend auto tag_invoke(types::Tag< function::monad::fail >, Self &&self, F &&function) -> R
Definition expected.h:294
constexpr auto value_or(U &&default_value) &&-> T
Definition expected.h:206
constexpr auto emplace(Args &&... args) -> T &
Definition expected.h:224
constexpr auto operator*() &&-> T &&
Definition expected.h:158
constexpr auto value() const &&-> T const &&
Definition expected.h:176
constexpr auto operator*() const &-> T const &
Definition expected.h:157
constexpr Expected(types::InPlace, Args &&... args)
Definition expected.h:97
constexpr auto value() const &-> T const &
Definition expected.h:168
constexpr friend auto operator==(Expected const &a, Expected< U, G > const &b) -> bool
Definition expected.h:245
constexpr auto optional_value() const &-> Optional< T > requires(concepts::CopyConstructible< T >)
Definition expected.h:210
constexpr auto error() &&-> E &&
Definition expected.h:189
constexpr friend auto operator==(Expected const &a, Unexpected< G > const &b) -> bool
Definition expected.h:262
constexpr auto error() const &-> E const &
Definition expected.h:185
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:303
constexpr auto value() &&-> T &&
Definition expected.h:172
constexpr Expected(Expected &&other)
Definition expected.h:56
util::RebindableBox< T > m_value
Definition expected.h:403
constexpr auto __try_did_succeed() &&-> Expected
Definition expected.h:237
constexpr auto error() const &&-> E const &&
Definition expected.h:193
constexpr auto emplace(std::initializer_list< U > list, Args &&... args) -> T &
Definition expected.h:230
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:129
constexpr Expected(Expected const &other)
Definition expected.h:49
constexpr auto operator*() const &&-> T const &&
Definition expected.h:159
constexpr Expected()
Definition expected.h:38
constexpr ~Expected()
Definition expected.h:117
util::RebindableBox< E > m_error
Definition expected.h:404
constexpr auto __try_did_fail() &&-> Unexpected< E >
Definition expected.h:234
constexpr auto operator->()
Definition expected.h:153
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:284
constexpr auto error() &-> E &
Definition expected.h:181
constexpr auto operator->() const
Definition expected.h:154
Definition expected_forward_declaration.h:8
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 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
constexpr auto nullopt
Definition nullopt.h:15
Expected(T &&) -> Expected< meta::UnwrapRefDecay< T >, void >
constexpr auto in_place
Definition in_place.h:8