13#include <initializer_list>
16#include <system_error>
21#if defined(__has_include)
22# if __has_include(<version>)
27#if defined(__cpp_lib_expected) && __cpp_lib_expected >= 202202L
29# define THREADSCHEDULE_HAS_STD_EXPECTED 1
31# define THREADSCHEDULE_HAS_STD_EXPECTED 0
34#ifdef __cpp_exceptions
35# define THREADSCHEDULE_EXPECTED_THROW(ex) throw ex
37# define THREADSCHEDULE_EXPECTED_THROW(ex) ::std::terminate()
40#if defined(__cpp_lib_constexpr_exceptions) && __cpp_lib_constexpr_exceptions >= 202502L
41# define THREADSCHEDULE_EXPECTED_EXCEPTION_CONSTEXPR constexpr
43# define THREADSCHEDULE_EXPECTED_EXCEPTION_CONSTEXPR
72 what() const noexcept ->
char const*
override
74 return "bad expected access";
79class bad_expected_access :
public bad_expected_access<void>
84 what() const noexcept ->
char const*
override
86 return bad_expected_access<void>::what();
88 [[nodiscard]]
constexpr auto
98 [[nodiscard]]
constexpr auto
101 return std::move(error_);
106 return std::move(error_);
145 template <
typename G = E, std::enable_if_t<!std::is_same_v<detail::expected_remove_cvref_t<G>, unexpected>
146 && !std::is_same_v<detail::expected_remove_cvref_t<G>, std::in_place_t>
147 && std::is_constructible_v<E, G>,
152 template <
typename... Args, std::enable_if_t<std::is_constructible_v<E, Args...>,
int> = 0>
153 constexpr explicit unexpected(std::in_place_t, Args&&... args) : error_(
std::forward<Args>(args)...)
156 template <
typename U,
typename... Args,
157 std::enable_if_t<std::is_constructible_v<E, std::initializer_list<U>&, Args...>,
int> = 0>
158 constexpr explicit unexpected(std::in_place_t, std::initializer_list<U> list, Args&&... args)
159 : error_(list,
std::forward<Args>(args)...)
162 [[nodiscard]]
constexpr auto
172 [[nodiscard]]
constexpr auto
175 return std::move(error_);
180 return std::move(error_);
186 static_assert(std::is_swappable_v<E>);
188 swap(error_, other.error_);
191 template <
typename G = E, std::enable_if_t<std::is_swappable_v<E>, G>* =
nullptr>
192 friend constexpr void
198 template <
typename G>
199 friend constexpr auto
202 return lhs.error() == rhs.error();
204 template <
typename G>
205 friend constexpr auto
208 return !(lhs == rhs);
218template <
typename T,
typename E = std::error_code>
225struct expected_value_tag
228struct expected_error_tag
231struct expected_from_other_tag
234struct expected_invoke_tag
238template <
bool Enabled>
239struct expected_move_constructor
243struct expected_move_constructor<false>
245 expected_move_constructor() =
default;
246 expected_move_constructor(expected_move_constructor
const&) =
default;
247 expected_move_constructor(expected_move_constructor&&) =
delete;
248 auto operator=(expected_move_constructor
const&) -> expected_move_constructor& =
default;
249 auto operator=(expected_move_constructor&&) -> expected_move_constructor& =
default;
250 ~expected_move_constructor() =
default;
254expected_in_constant_evaluation() noexcept ->
bool
256#if defined(_MSC_VER) && !defined(__clang__)
257 return __builtin_is_constant_evaluated();
258#elif defined(__has_builtin)
259# if __has_builtin(__builtin_is_constant_evaluated)
260 return __builtin_is_constant_evaluated();
270template <std::size_t I,
typename Storage,
typename... Args>
272emplace_expected_storage(Storage& storage,
int, Args&&... args)
noexcept
273 ->
decltype(construct_at(std::addressof(storage), std::in_place_index<I>, std::in_place,
274 std::forward<Args>(args)...),
277 if (!expected_in_constant_evaluation())
279 storage.template emplace<I>(std::in_place, std::forward<Args>(args)...);
284 auto* address = std::addressof(storage);
285 std::destroy_at(address);
286 construct_at(address, std::in_place_index<I>, std::in_place, std::forward<Args>(args)...);
288template <std::size_t I,
typename Storage,
typename... Args>
290emplace_expected_storage(Storage& storage,
long, Args&&... args)
noexcept
292 storage.template emplace<I>(std::in_place, std::forward<Args>(args)...);
295template <
typename T,
typename E>
299inline constexpr bool valid_expected_value_v
301 || (std::is_object_v<T> && !std::is_array_v<T> && !std::is_same_v<std::remove_cv_t<T>, std::in_place_t>
305inline constexpr bool is_expected_v =
false;
306template <
typename T,
typename E>
307inline constexpr bool is_expected_v<expected<T, E>> =
true;
309template <
typename T,
typename Source>
310using constructs_from_expected
311 = std::disjunction<std::is_constructible<T, Source&>, std::is_constructible<T, Source const&>,
312 std::is_constructible<T, Source&&>, std::is_constructible<T, Source const&&>>;
314template <
typename T,
typename Source>
315using converts_from_expected = std::disjunction<constructs_from_expected<T, Source>, std::is_convertible<Source&, T>,
316 std::is_convertible<Source const&, T>, std::is_convertible<Source&&, T>,
317 std::is_convertible<Source const&&, T>>;
319template <
typename T,
typename E,
typename Source,
typename Value,
typename Error>
320inline constexpr bool expected_can_convert_v = std::conjunction_v<
321 std::negation<std::is_same<expected<T, E>, Source>>, std::is_constructible<T, Value>,
322 std::is_constructible<E, Error>,
323 std::disjunction<std::is_same<std::remove_cv_t<T>,
bool>, std::negation<converts_from_expected<T, Source>>>,
324 std::negation<constructs_from_expected<unexpected<E>, Source>>>;
326template <
typename T,
typename E,
typename U>
327inline constexpr bool expected_can_forward_v
328 = !std::is_same_v<std::decay_t<U>, expected<T, E>> && !std::is_same_v<std::decay_t<U>, std::in_place_t>
330 && !(std::is_same_v<std::remove_cv_t<T>,
bool> && is_expected_v<std::decay_t<U>>)
331 && std::is_constructible_v<T, U>;
333template <
typename L,
typename R,
typename =
void>
334inline constexpr bool expected_equality_comparable_v =
false;
335template <
typename L,
typename R>
337 expected_equality_comparable_v<L, R, std::void_t<decltype(std::declval<L const&>() == std::declval<R const&>())>>
338 = std::is_convertible_v<
decltype(std::declval<L const&>() == std::declval<R const&>()),
bool>;
341require_expected_state(
bool valid)
noexcept
347template <
typename F,
typename T,
typename From>
348using expected_require_constructible
349 = std::enable_if_t<std::conjunction_v<std::is_constructible<T, From>, std::is_same<F, F>>,
int>;
351template <
typename T,
typename E>
352inline constexpr bool expected_can_swap_v
353 = std::is_swappable_v<T> && std::is_swappable_v<E> && std::is_move_constructible_v<T>
354 && std::is_move_constructible_v<E>
355 && (std::is_nothrow_move_constructible_v<T> || std::is_nothrow_move_constructible_v<E>);
357template <
typename T,
typename E,
typename U,
typename G,
typename Error>
358inline constexpr bool expected_void_can_convert_v
359 = std::conjunction_v<std::negation<std::is_same<expected<T, E>, expected<U, G>>>, std::is_void<U>,
360 std::is_constructible<E, Error>,
361 std::negation<constructs_from_expected<unexpected<E>, expected<U, G>>>>;
364struct expected_value_holder
366 template <
typename... Args>
367 explicit constexpr expected_value_holder(std::in_place_t,
368 Args&&... args)
noexcept(std::is_nothrow_constructible_v<T, Args...>)
369 : value(std::forward<Args>(args)...)
372 template <
typename F,
typename... Args>
373 explicit constexpr expected_value_holder(std::in_place_t, expected_invoke_tag, F&& f, Args&&... args)
374 : value(std::invoke(std::forward<F>(f), std::forward<Args>(args)...))
381struct expected_error_holder
383 template <
typename... Args>
384 explicit constexpr expected_error_holder(std::in_place_t,
385 Args&&... args)
noexcept(std::is_nothrow_constructible_v<E, Args...>)
386 : error(std::forward<Args>(args)...)
389 template <
typename F,
typename... Args>
390 explicit constexpr expected_error_holder(std::in_place_t, expected_invoke_tag, F&& f, Args&&... args)
391 : error(std::invoke(std::forward<F>(f), std::forward<Args>(args)...))
397template <
typename T,
typename E>
398class expected_storage_common
399 :
private expected_move_constructor<std::is_move_constructible_v<T> && std::is_move_constructible_v<E>>
402 using value_holder = expected_value_holder<T>;
403 using error_holder = expected_error_holder<E>;
405 template <
typename... Args>
406 explicit constexpr expected_storage_common(expected_value_tag, Args&&... args)
407 : data_(std::in_place_index<0>, std::in_place, std::forward<Args>(args)...)
410 template <
typename... Args>
411 explicit constexpr expected_storage_common(expected_error_tag, Args&&... args)
412 : data_(std::in_place_index<1>, std::in_place, std::forward<Args>(args)...)
416 template <
typename Source>
417 explicit constexpr expected_storage_common(expected_from_other_tag, Source&& source)
418 : data_(make_from_other(std::forward<Source>(source)))
422 expected_storage_common(expected_storage_common
const&) =
default;
423 expected_storage_common(expected_storage_common&&) =
default;
424 auto operator=(expected_storage_common
const&) -> expected_storage_common& =
default;
425 auto operator=(expected_storage_common&&) -> expected_storage_common& =
default;
426 ~expected_storage_common() =
default;
428 [[nodiscard]]
constexpr auto
429 has_value() const noexcept ->
bool
431 return data_.index() == 0;
436 return std::get<0>(data_).value;
438 [[nodiscard]]
constexpr auto
441 return std::get<0>(data_).value;
446 return std::move(std::get<0>(data_).value);
448 [[nodiscard]]
constexpr auto
451 return std::move(std::get<0>(data_).value);
456 return std::get<1>(data_).error;
458 [[nodiscard]]
constexpr auto
461 return std::get<1>(data_).error;
466 return std::move(std::get<1>(data_).error);
468 [[nodiscard]]
constexpr auto
471 return std::move(std::get<1>(data_).error);
474 template <
typename U>
476 assign_value(U&& source)
479 value() = std::forward<U>(source);
481 replace_with_value(std::forward<U>(source));
484 template <
typename G>
486 assign_error(G&& source)
489 replace_with_error(std::forward<G>(source));
491 error() = std::forward<G>(source);
494 template <
typename... Args>
496 emplace_value(Args&&... args)
noexcept -> T&
498 emplace_nothrow<0>(std::forward<Args>(args)...);
503 copy_assign(expected_storage_common
const& other)
505 if (has_value() &&
other.has_value())
506 value() =
other.value();
507 else if (!has_value() && !
other.has_value())
508 error() =
other.error();
509 else if (
other.has_value())
510 replace_with_value(
other.value());
512 replace_with_error(
other.error());
516 move_assign(expected_storage_common&& other)
518 if (has_value() &&
other.has_value())
519 value() = std::move(other).value();
520 else if (!has_value() && !
other.has_value())
521 error() = std::move(other).error();
522 else if (
other.has_value())
523 replace_with_value(std::move(other).value());
525 replace_with_error(std::move(other).error());
529 swap_storage(expected_storage_common& other)
noexcept(std::is_nothrow_move_constructible_v<T>
530 && std::is_nothrow_move_constructible_v<E>
531 && std::is_nothrow_swappable_v<T>
532 && std::is_nothrow_swappable_v<E>)
534 if (has_value() &&
other.has_value())
539 else if (!has_value() && !
other.has_value())
544 else if (has_value())
545 swap_value_error(*
this, other);
547 swap_value_error(other, *
this);
551 using storage_type = std::variant<value_holder, error_holder>;
553 template <
typename Source>
554 static constexpr auto
555 make_from_other(Source&& source) -> storage_type
557 if (!source.has_value())
558 return storage_type(std::in_place_index<1>, std::in_place, std::forward<Source>(source).error());
559 return storage_type(std::in_place_index<0>, std::in_place, *std::forward<Source>(source));
562 template <std::size_t I,
typename... Args>
564 emplace_nothrow(Args&&... args)
noexcept
566 emplace_expected_storage<I>(data_, 0, std::forward<Args>(args)...);
569#ifdef __cpp_exceptions
570 template <std::size_t I,
typename Backup,
typename... Args>
571# if defined(__cpp_constexpr_exceptions)
575 emplace_with_rollback(Backup& backup, Args&&... args)
579 data_.template emplace<I>(std::in_place, std::forward<Args>(args)...);
583 data_.template emplace<1 - I>(std::in_place, std::move(backup));
589 template <std::size_t I,
typename Backup,
typename... Args>
591 emplace_with_backup(Backup&& backup, Args&&... args)
593#if defined(__cpp_exceptions) && defined(__cpp_constexpr_exceptions)
594 emplace_with_rollback<I>(backup, std::forward<Args>(args)...);
596# ifdef __cpp_exceptions
598 if (!expected_in_constant_evaluation())
600 emplace_with_rollback<I>(backup, std::forward<Args>(args)...);
605 data_.template emplace<I>(std::in_place, std::forward<Args>(args)...);
609 template <
typename U>
611 replace_with_value(U&& source)
613 if constexpr (std::is_nothrow_constructible_v<T, U>)
614 emplace_nothrow<0>(std::forward<U>(source));
615 else if constexpr (std::is_nothrow_move_constructible_v<T>)
617 T replacement(std::forward<U>(source));
618 emplace_nothrow<0>(std::move(replacement));
622 static_assert(std::is_nothrow_move_constructible_v<E>);
623 E backup(std::move(error()));
624 emplace_with_backup<0>(backup, std::forward<U>(source));
628 template <
typename G>
630 replace_with_error(G&& source)
632 if constexpr (std::is_nothrow_constructible_v<E, G>)
633 emplace_nothrow<1>(std::forward<G>(source));
634 else if constexpr (std::is_nothrow_move_constructible_v<E>)
636 E replacement(std::forward<G>(source));
637 emplace_nothrow<1>(std::move(replacement));
641 static_assert(std::is_nothrow_move_constructible_v<T>);
642 T backup(std::move(value()));
643 emplace_with_backup<1>(backup, std::forward<G>(source));
647 static constexpr void
648 swap_value_error(expected_storage_common& with_value, expected_storage_common& with_error)
650 if constexpr (std::is_nothrow_move_constructible_v<E>)
652 E backup(std::move(with_error.error()));
653 with_error.template emplace_with_backup<0>(backup, std::move(with_value.value()));
654 with_value.template emplace_nothrow<1>(std::move(backup));
658 static_assert(std::is_nothrow_move_constructible_v<T>);
659 T backup(std::move(with_value.value()));
660 with_value.template emplace_with_backup<1>(backup, std::move(with_error.error()));
661 with_error.template emplace_nothrow<0>(std::move(backup));
668template <
typename T,
typename E>
669inline constexpr bool expected_copy_assignable_v
670 = std::is_copy_constructible_v<T> && std::is_copy_constructible_v<E> && std::is_copy_assignable_v<T>
671 && std::is_copy_assignable_v<E>
672 && (std::is_nothrow_move_constructible_v<T> || std::is_nothrow_move_constructible_v<E>);
673template <
typename T,
typename E>
674inline constexpr bool expected_move_assignable_v
675 = std::is_move_constructible_v<T> && std::is_move_constructible_v<E> && std::is_move_assignable_v<T>
676 && std::is_move_assignable_v<E>
677 && (std::is_nothrow_move_constructible_v<T> || std::is_nothrow_move_constructible_v<E>);
679enum class expected_assignment
686template <
typename T,
typename E>
687inline constexpr auto expected_copy_assignment_v
688 = !expected_copy_assignable_v<T, E> ? expected_assignment::unavailable
689 : std::is_trivially_copy_constructible_v<T> && std::is_trivially_copy_constructible_v<E>
690 && std::is_trivially_copy_assignable_v<T> && std::is_trivially_copy_assignable_v<E>
691 && std::is_trivially_destructible_v<T> && std::is_trivially_destructible_v<E>
692 ? expected_assignment::trivial
693 : expected_assignment::custom;
695template <
typename T,
typename E>
696inline constexpr auto expected_move_assignment_v
697 = !expected_move_assignable_v<T, E> ? expected_assignment::unavailable
698 : std::is_trivially_move_constructible_v<T> && std::is_trivially_move_constructible_v<E>
699 && std::is_trivially_move_assignable_v<T> && std::is_trivially_move_assignable_v<E>
700 && std::is_trivially_destructible_v<T> && std::is_trivially_destructible_v<E>
701 ? expected_assignment::trivial
702 : expected_assignment::custom;
704template <
typename T,
typename E, expected_assignment Copy = expected_copy_assignment_v<T, E>>
705class expected_copy_storage :
public expected_storage_common<T, E>
708 using expected_storage_common<T, E>::expected_storage_common;
711template <
typename T,
typename E>
712class expected_copy_storage<T, E, expected_assignment::custom> :
public expected_storage_common<T, E>
715 using expected_storage_common<T, E>::expected_storage_common;
716 expected_copy_storage(expected_copy_storage
const&) =
default;
717 expected_copy_storage(expected_copy_storage&&) =
default;
719 operator=(expected_copy_storage
const& other) -> expected_copy_storage&
721 this->copy_assign(other);
724 auto operator=(expected_copy_storage&&) -> expected_copy_storage& =
default;
725 ~expected_copy_storage() =
default;
728template <
typename T,
typename E>
729class expected_copy_storage<T, E, expected_assignment::unavailable> :
public expected_storage_common<T, E>
732 using expected_storage_common<T, E>::expected_storage_common;
733 expected_copy_storage(expected_copy_storage
const&) =
default;
734 expected_copy_storage(expected_copy_storage&&) =
default;
735 auto operator=(expected_copy_storage
const&) -> expected_copy_storage& =
delete;
736 auto operator=(expected_copy_storage&&) -> expected_copy_storage& =
default;
737 ~expected_copy_storage() =
default;
740template <
typename T,
typename E, expected_assignment Move = expected_move_assignment_v<T, E>>
741class expected_storage :
public expected_copy_storage<T, E>
744 using expected_copy_storage<T, E>::expected_copy_storage;
747template <
typename T,
typename E>
748class expected_storage<T, E, expected_assignment::custom> :
public expected_copy_storage<T, E>
751 using expected_copy_storage<T, E>::expected_copy_storage;
752 expected_storage(expected_storage
const&) =
default;
753 expected_storage(expected_storage&&) =
default;
754 auto operator=(expected_storage
const&) -> expected_storage& =
default;
756 operator=(expected_storage&& other)
noexcept(std::is_nothrow_move_constructible_v<T>
757 && std::is_nothrow_move_constructible_v<E>
758 && std::is_nothrow_move_assignable_v<T>
759 && std::is_nothrow_move_assignable_v<E>) -> expected_storage&
761 this->move_assign(std::move(other));
764 ~expected_storage() =
default;
767template <
typename T,
typename E>
768class expected_storage<T, E, expected_assignment::unavailable> :
public expected_copy_storage<T, E>
771 using expected_copy_storage<T, E>::expected_copy_storage;
772 expected_storage(expected_storage
const&) =
default;
773 expected_storage(expected_storage&&) =
default;
774 auto operator=(expected_storage
const&) -> expected_storage& =
default;
775 auto operator=(expected_storage&&) -> expected_storage& =
delete;
776 ~expected_storage() =
default;
782template <
typename T,
typename E>
785 static_assert(!std::is_void_v<T> && detail::valid_expected_value_v<T>);
792 template <
typename U>
795 template <
typename U = T, std::enable_if_t<std::is_default_constructible_v<U>,
int> = 0>
799 template <
typename U = T, std::enable_if_t<!std::is_default_constructible_v<U>,
int> = 0>
808 template <
typename U = std::remove_cv_t<T>,
809 std::enable_if_t<detail::expected_can_forward_v<T, E, U> && std::is_convertible_v<U, T>,
int> = 0>
813 template <
typename U = std::remove_cv_t<T>,
814 std::enable_if_t<detail::expected_can_forward_v<T, E, U> && !std::is_convertible_v<U, T>,
int> = 0>
819 template <
typename U,
typename G,
820 std::enable_if_t<detail::expected_can_convert_v<T, E, expected<U, G>, U
const&, G
const&>
821 && std::is_convertible_v<U const&, T> && std::is_convertible_v<G const&, E>,
826 template <
typename U,
typename G,
827 std::enable_if_t<detail::expected_can_convert_v<T, E, expected<U, G>, U
const&, G
const&>
828 && !(std::is_convertible_v<U const&, T> && std::is_convertible_v<G const&, E>),
833 template <
typename U,
typename G,
834 std::enable_if_t<detail::expected_can_convert_v<T, E, expected<U, G>, U, G> && std::is_convertible_v<U, T>
835 && std::is_convertible_v<G, E>,
840 template <
typename U,
typename G,
841 std::enable_if_t<detail::expected_can_convert_v<T, E, expected<U, G>, U, G>
842 && !(std::is_convertible_v<U, T> && std::is_convertible_v<G, E>),
848 template <
typename... Args, std::enable_if_t<std::is_constructible_v<T, Args...>,
int> = 0>
849 constexpr explicit expected(std::in_place_t, Args&&... args)
850 : storage_(
detail::expected_value_tag{},
std::forward<Args>(args)...)
853 template <
typename U,
typename... Args,
854 std::enable_if_t<std::is_constructible_v<T, std::initializer_list<U>&, Args...>,
int> = 0>
855 constexpr explicit expected(std::in_place_t, std::initializer_list<U> list, Args&&... args)
856 : storage_(
detail::expected_value_tag{}, list,
std::forward<Args>(args)...)
859 template <
typename G,
860 std::enable_if_t<std::is_constructible_v<E, G const&> && std::is_convertible_v<G const&, E>,
int> = 0>
864 template <
typename G,
865 std::enable_if_t<std::is_constructible_v<E, G const&> && !std::is_convertible_v<G const&, E>,
int> = 0>
869 template <
typename G, std::enable_if_t<std::is_constructible_v<E, G> && std::is_convertible_v<G, E>,
int> = 0>
873 template <
typename G, std::enable_if_t<std::is_constructible_v<E, G> && !std::is_convertible_v<G, E>,
int> = 0>
875 : storage_(
detail::expected_error_tag{},
std::move(source).
error())
878 template <
typename... Args, std::enable_if_t<std::is_constructible_v<E, Args...>,
int> = 0>
880 : storage_(
detail::expected_error_tag{},
std::forward<Args>(args)...)
884 template <
typename U,
typename... Args,
885 std::enable_if_t<std::is_constructible_v<E, std::initializer_list<U>&, Args...>,
int> = 0>
887 : storage_(
detail::expected_error_tag{}, list,
std::forward<Args>(args)...)
891 template <
typename U = std::remove_cv_t<T>,
892 std::enable_if_t<!std::is_same_v<detail::expected_remove_cvref_t<U>, expected>
893 && !detail::is_unexpected_v<detail::expected_remove_cvref_t<U>>
894 && std::is_constructible_v<T, U> && std::is_assignable_v<T&, U>
895 && (std::is_nothrow_constructible_v<T, U> || std::is_nothrow_move_constructible_v<T>
896 || std::is_nothrow_move_constructible_v<E>),
901 storage_.assign_value(std::forward<U>(
value));
904 template <
typename G, std::enable_if_t<std::is_constructible_v<E, G const&> && std::is_assignable_v<E&, G const&>
905 && (std::is_nothrow_constructible_v<E, G const&>
906 || std::is_nothrow_move_constructible_v<E>
907 || std::is_nothrow_move_constructible_v<T>),
912 storage_.assign_error(
error.error());
915 template <
typename G,
916 std::enable_if_t<std::is_constructible_v<E, G> && std::is_assignable_v<E&, G>
917 && (std::is_nothrow_constructible_v<E, G> || std::is_nothrow_move_constructible_v<E>
918 || std::is_nothrow_move_constructible_v<T>),
923 storage_.assign_error(std::move(
error).
error());
927 [[nodiscard]]
constexpr auto
930 return storage_.has_value();
932 [[nodiscard]]
constexpr auto
938 operator bool() const noexcept
945 return std::addressof(storage_.value());
950 return std::addressof(storage_.value());
955 return storage_.value();
957 [[nodiscard]]
constexpr auto
960 return storage_.value();
965 return std::move(storage_).value();
967 [[nodiscard]]
constexpr auto
970 return std::move(storage_).value();
976 static_assert(std::is_copy_constructible_v<E>);
979 return storage_.value();
981 [[nodiscard]]
constexpr auto
984 static_assert(std::is_copy_constructible_v<E>);
987 return storage_.value();
992 static_assert(std::is_copy_constructible_v<E> && std::is_constructible_v<E, E&&>);
995 return std::move(storage_).value();
997 [[nodiscard]]
constexpr auto
1000 static_assert(std::is_copy_constructible_v<E> && std::is_constructible_v<E, E const&&>);
1003 return std::move(storage_).value();
1008 return storage_.error();
1010 [[nodiscard]]
constexpr auto
1013 return storage_.error();
1018 return std::move(storage_).error();
1020 [[nodiscard]]
constexpr auto
1023 return std::move(storage_).error();
1026 template <
typename U = std::remove_cv_t<T>>
1030 static_assert(std::is_copy_constructible_v<T> && std::is_convertible_v<U, T>);
1031 return has_value() ? storage_.value() :
static_cast<T
>(std::forward<U>(fallback));
1033 template <
typename U = std::remove_cv_t<T>>
1037 static_assert(std::is_move_constructible_v<T> && std::is_convertible_v<U, T>);
1038 return has_value() ? std::move(storage_).value() :
static_cast<T
>(std::forward<U>(fallback));
1040 template <
typename G = E>
1044 static_assert(std::is_copy_constructible_v<E> && std::is_convertible_v<G, E>);
1046 return std::forward<G>(fallback);
1047 return storage_.error();
1049 template <
typename G = E>
1053 static_assert(std::is_move_constructible_v<E> && std::is_convertible_v<G, E>);
1055 return std::forward<G>(fallback);
1056 return std::move(storage_).error();
1058 template <
typename... Args, std::enable_if_t<std::is_nothrow_constructible_v<T, Args...>,
int> = 0>
1062 return storage_.emplace_value(std::forward<Args>(args)...);
1064 template <
typename U,
typename... Args,
1065 std::enable_if_t<std::is_nothrow_constructible_v<T, std::initializer_list<U>&, Args...>,
int> = 0>
1067 emplace(std::initializer_list<U> list, Args&&... args)
noexcept -> T&
1069 return storage_.emplace_value(list, std::forward<Args>(args)...);
1071 template <
typename U = T, std::enable_if_t<detail::expected_can_swap_v<T, E>, U>* =
nullptr>
1073 swap(
expected& other)
noexcept(std::is_nothrow_move_constructible_v<T> && std::is_nothrow_move_constructible_v<E>
1074 && std::is_nothrow_swappable_v<T> && std::is_nothrow_swappable_v<E>)
1076 storage_.swap_storage(other.storage_);
1079 template <
typename F, detail::expected_require_constructible<F, E, E&> = 0>
1083 return and_then_impl(*
this, std::forward<F>(f));
1085 template <
typename F, detail::expected_require_constructible<F, E, E const&> = 0>
1089 return and_then_impl(*
this, std::forward<F>(f));
1091 template <
typename F, detail::expected_require_constructible<F, E, E&&> = 0>
1095 return and_then_impl(std::move(*
this), std::forward<F>(f));
1097 template <
typename F, detail::expected_require_constructible<F, E, E const&&> = 0>
1101 return and_then_impl(std::move(*
this), std::forward<F>(f));
1103 template <
typename F, detail::expected_require_constructible<F, T, T&> = 0>
1107 return or_else_impl(*
this, std::forward<F>(f));
1109 template <
typename F, detail::expected_require_constructible<F, T, T const&> = 0>
1113 return or_else_impl(*
this, std::forward<F>(f));
1115 template <
typename F, detail::expected_require_constructible<F, T, T&&> = 0>
1119 return or_else_impl(std::move(*
this), std::forward<F>(f));
1121 template <
typename F, detail::expected_require_constructible<F, T, T const&&> = 0>
1125 return or_else_impl(std::move(*
this), std::forward<F>(f));
1127 template <
typename F, detail::expected_require_constructible<F, E, E&> = 0>
1131 return transform_impl(*
this, std::forward<F>(f));
1133 template <
typename F, detail::expected_require_constructible<F, E, E const&> = 0>
1137 return transform_impl(*
this, std::forward<F>(f));
1139 template <
typename F, detail::expected_require_constructible<F, E, E&&> = 0>
1143 return transform_impl(std::move(*
this), std::forward<F>(f));
1145 template <
typename F, detail::expected_require_constructible<F, E, E const&&> = 0>
1149 return transform_impl(std::move(*
this), std::forward<F>(f));
1151 template <
typename F, detail::expected_require_constructible<F, T, T&> = 0>
1155 return transform_error_impl(*
this, std::forward<F>(f));
1157 template <
typename F, detail::expected_require_constructible<F, T, T const&> = 0>
1161 return transform_error_impl(*
this, std::forward<F>(f));
1163 template <
typename F, detail::expected_require_constructible<F, T, T&&> = 0>
1167 return transform_error_impl(std::move(*
this), std::forward<F>(f));
1169 template <
typename F, detail::expected_require_constructible<F, T, T const&&> = 0>
1173 return transform_error_impl(std::move(*
this), std::forward<F>(f));
1176#if THREADSCHEDULE_HAS_STD_EXPECTED
1177 template <
typename U = T,
typename G = E,
1178 std::enable_if_t<std::is_copy_constructible_v<U> && std::is_copy_constructible_v<G>,
int> = 0>
1180 operator std::expected<T, E>() const&
1183 return std::expected<T, E>(std::in_place, storage_.value());
1184 return std::expected<T, E>(std::unexpect, storage_.error());
1186 template <
typename U = T,
typename G = E,
1187 std::enable_if_t<std::is_move_constructible_v<U> && std::is_move_constructible_v<G>,
int> = 0>
1189 operator std::expected<T, E>() &&
1192 return std::expected<T, E>(std::in_place, std::move(storage_).
value());
1193 return std::expected<T, E>(std::unexpect, std::move(storage_).
error());
1197 template <
typename T2,
typename E2,
1198 std::enable_if_t<!std::is_void_v<T2> && detail::expected_equality_comparable_v<T, T2>
1199 && detail::expected_equality_comparable_v<E, E2>,
1201 friend constexpr auto
1204 if (lhs.has_value() != rhs.has_value())
1206 if (lhs.has_value())
1207 return *lhs == *rhs;
1208 return lhs.error() == rhs.error();
1210 template <
typename T2,
typename E2,
1211 std::enable_if_t<!std::is_void_v<T2> && detail::expected_equality_comparable_v<T, T2>
1212 && detail::expected_equality_comparable_v<E, E2>,
1214 friend constexpr auto
1217 return !(lhs == rhs);
1219 template <
typename E2, std::enable_if_t<detail::expected_equality_comparable_v<E, E2>,
int> = 0>
1220 friend constexpr auto
1223 if (lhs.has_value())
1225 return lhs.error() == rhs.error();
1227 template <
typename E2, std::enable_if_t<detail::expected_equality_comparable_v<E, E2>,
int> = 0>
1228 friend constexpr auto
1233 template <
typename E2, std::enable_if_t<detail::expected_equality_comparable_v<E, E2>,
int> = 0>
1234 friend constexpr auto
1237 return !(lhs == rhs);
1239 template <
typename E2, std::enable_if_t<detail::expected_equality_comparable_v<E, E2>,
int> = 0>
1240 friend constexpr auto
1243 return !(rhs == lhs);
1247 template <
typename,
typename>
1249 template <
typename,
typename>
1252 template <
typename Tag,
typename F,
typename... Args>
1253 constexpr explicit expected(Tag tag, detail::expected_invoke_tag, F&& f, Args&&... args)
1254 : storage_(tag,
detail::expected_invoke_tag{},
std::forward<F>(f),
std::forward<Args>(args)...)
1258 template <
typename Self,
typename F>
1259 static constexpr auto
1260 and_then_impl(Self&& self, F&& f)
1264 static_assert(detail::is_expected_v<result_type> && std::is_same_v<typename result_type::error_type, E>);
1265 if (self.has_value())
1266 return result_type(std::invoke(std::forward<F>(f), std::forward<Self>(self).storage_.value()));
1267 return result_type(
unexpect, std::forward<Self>(self).
error());
1269 template <
typename Self,
typename F>
1270 static constexpr auto
1271 or_else_impl(Self&& self, F&& f)
1275 static_assert(detail::is_expected_v<result_type> && std::is_same_v<typename result_type::value_type, T>);
1276 if (self.has_value())
1277 return result_type(std::in_place, std::forward<Self>(self).storage_.value());
1278 return result_type(std::invoke(std::forward<F>(f), std::forward<Self>(self).
error()));
1280 template <
typename Self,
typename F>
1281 static constexpr auto
1282 transform_impl(Self&& self, F&& f)
1284 using result_value = std::remove_cv_t<std::invoke_result_t<F, decltype(std::forward<Self>(self).storage_.value())>>;
1285 static_assert(detail::valid_expected_value_v<result_value>);
1287 if (!self.has_value())
1288 return result_type(
unexpect, std::forward<Self>(self).error());
1289 if constexpr (std::is_void_v<result_value>)
1291 std::invoke(std::forward<F>(f), std::forward<Self>(self).storage_.value());
1292 return result_type();
1295 return result_type(detail::expected_value_tag{}, detail::expected_invoke_tag{}, std::forward<F>(f),
1296 std::forward<Self>(self).storage_.value());
1298 template <
typename Self,
typename F>
1299 static constexpr auto
1300 transform_error_impl(Self&& self, F&& f)
1302 using result_error = std::remove_cv_t<std::invoke_result_t<F, decltype(std::forward<Self>(self).error())>>;
1305 if (self.has_value())
1306 return result_type(std::in_place, std::forward<Self>(self).storage_.value());
1307 return result_type(detail::expected_error_tag{}, detail::expected_invoke_tag{}, std::forward<F>(f),
1308 std::forward<Self>(self).error());
1311 detail::expected_storage<T, E> storage_;
1317template <
typename T,
typename E>
1321 using storage_type = std::optional<expected_error_holder<E>>;
1329 template <
typename U>
1336 typename U,
typename G,
1337 std::enable_if_t<detail::expected_void_can_convert_v<T, E, U, G, G const&> && std::is_convertible_v<G const&, E>,
1343 typename U,
typename G,
1344 std::enable_if_t<detail::expected_void_can_convert_v<T, E, U, G, G const&> && !std::is_convertible_v<G const&, E>,
1349 template <
typename U,
typename G,
1350 std::enable_if_t<detail::expected_void_can_convert_v<T, E, U, G, G> && std::is_convertible_v<G, E>,
int>
1355 template <
typename U,
typename G,
1356 std::enable_if_t<detail::expected_void_can_convert_v<T, E, U, G, G> && !std::is_convertible_v<G, E>,
int>
1362 template <
typename... Args, std::enable_if_t<std::is_constructible_v<E, Args...>,
int> = 0>
1364 : storage_(
std::in_place,
std::in_place,
std::forward<Args>(args)...)
1367 template <
typename G,
1368 std::enable_if_t<std::is_constructible_v<E, G const&> && std::is_convertible_v<G const&, E>,
int> = 0>
1372 template <
typename G,
1373 std::enable_if_t<std::is_constructible_v<E, G const&> && !std::is_convertible_v<G const&, E>,
int> = 0>
1377 template <
typename G, std::enable_if_t<std::is_constructible_v<E, G> && std::is_convertible_v<G, E>,
int> = 0>
1381 template <
typename G, std::enable_if_t<std::is_constructible_v<E, G> && !std::is_convertible_v<G, E>,
int> = 0>
1383 : storage_(
std::in_place,
std::in_place,
std::move(source).
error())
1386 template <
typename U,
typename... Args,
1387 std::enable_if_t<std::is_constructible_v<E, std::initializer_list<U>&, Args...>,
int> = 0>
1389 : storage_(
std::in_place,
std::in_place, list,
std::forward<Args>(args)...)
1392 template <
typename G,
1393 std::enable_if_t<std::is_constructible_v<E, G const&> && std::is_assignable_v<E&, G const&>,
int> = 0>
1397 assign_error(
error.error());
1398 return static_cast<derived_type&
>(*this);
1400 template <
typename G, std::enable_if_t<std::is_constructible_v<E, G> && std::is_assignable_v<E&, G>,
int> = 0>
1405 return static_cast<derived_type&
>(*this);
1408 [[nodiscard]]
constexpr auto
1411 return !storage_.has_value();
1413 [[nodiscard]]
constexpr auto
1419 operator bool() const noexcept
1444 return storage_->error;
1446 [[nodiscard]]
constexpr auto
1450 return storage_->error;
1456 return std::move(storage_->error);
1458 [[nodiscard]]
constexpr auto
1462 return std::move(storage_->error);
1464 template <
typename G = E>
1468 static_assert(std::is_copy_constructible_v<E> && std::is_convertible_v<G, E>);
1470 return std::forward<G>(fallback);
1471 return storage_->error;
1473 template <
typename G = E>
1477 static_assert(std::is_move_constructible_v<E> && std::is_convertible_v<G, E>);
1479 return std::forward<G>(fallback);
1480 return std::move(storage_->error);
1487 template <
typename G = E, std::enable_if_t<std::is_move_constructible_v<E> && std::is_swappable_v<E>, G>* =
nullptr>
1489 swap(derived_type&
other)
noexcept(std::is_nothrow_move_constructible_v<E> && std::is_nothrow_swappable_v<E>)
1491 if (storage_ &&
other.storage_)
1494 swap(storage_->error,
other.storage_->error);
1497 other.move_error_from(*
this);
1498 else if (
other.storage_)
1499 move_error_from(
other);
1502 template <
typename F, detail::expected_require_constructible<F, E, E&> = 0>
1506 return and_then_impl(*
this, std::forward<F>(f));
1508 template <
typename F, detail::expected_require_constructible<F, E, E const&> = 0>
1512 return and_then_impl(*
this, std::forward<F>(f));
1514 template <
typename F, detail::expected_require_constructible<F, E, E&&> = 0>
1518 return and_then_impl(std::move(*
this), std::forward<F>(f));
1520 template <
typename F, detail::expected_require_constructible<F, E, E const&&> = 0>
1524 return and_then_impl(std::move(*
this), std::forward<F>(f));
1526 template <
typename F>
1530 return or_else_impl(*
this, std::forward<F>(f));
1532 template <
typename F>
1536 return or_else_impl(*
this, std::forward<F>(f));
1538 template <
typename F>
1542 return or_else_impl(std::move(*
this), std::forward<F>(f));
1544 template <
typename F>
1548 return or_else_impl(std::move(*
this), std::forward<F>(f));
1550 template <
typename F, detail::expected_require_constructible<F, E, E&> = 0>
1554 return transform_impl(*
this, std::forward<F>(f));
1556 template <
typename F, detail::expected_require_constructible<F, E, E const&> = 0>
1560 return transform_impl(*
this, std::forward<F>(f));
1562 template <
typename F, detail::expected_require_constructible<F, E, E&&> = 0>
1566 return transform_impl(std::move(*
this), std::forward<F>(f));
1568 template <
typename F, detail::expected_require_constructible<F, E, E const&&> = 0>
1572 return transform_impl(std::move(*
this), std::forward<F>(f));
1574 template <
typename F>
1578 return transform_error_impl(*
this, std::forward<F>(f));
1580 template <
typename F>
1584 return transform_error_impl(*
this, std::forward<F>(f));
1586 template <
typename F>
1590 return transform_error_impl(std::move(*
this), std::forward<F>(f));
1592 template <
typename F>
1596 return transform_error_impl(std::move(*
this), std::forward<F>(f));
1599#if THREADSCHEDULE_HAS_STD_EXPECTED
1600 template <
typename G = E, std::enable_if_t<std::is_copy_constructible_v<G>,
int> = 0>
1602 operator std::expected<T, E>() const&
1605 return std::expected<T, E>();
1606 return std::expected<T, E>(std::unexpect, storage_->error);
1608 template <
typename G = E, std::enable_if_t<std::is_move_constructible_v<G>,
int> = 0>
1610 operator std::expected<T, E>() &&
1613 return std::expected<T, E>();
1614 return std::expected<T, E>(std::unexpect, std::move(storage_->error));
1618 template <
typename T2,
typename E2,
1619 std::enable_if_t<std::is_void_v<T2> && expected_equality_comparable_v<E, E2>,
int> = 0>
1620 friend constexpr auto
1623 if (lhs.has_value() != rhs.has_value())
1625 if (lhs.has_value())
1627 return lhs.error() == rhs.error();
1629 template <
typename T2,
typename E2,
1630 std::enable_if_t<std::is_void_v<T2> && expected_equality_comparable_v<E, E2>,
int> = 0>
1631 friend constexpr auto
1634 return !(lhs == rhs);
1636 template <
typename E2, std::enable_if_t<detail::expected_equality_comparable_v<E, E2>,
int> = 0>
1637 friend constexpr auto
1640 if (lhs.has_value())
1642 return lhs.error() == rhs.error();
1644 template <
typename E2, std::enable_if_t<detail::expected_equality_comparable_v<E, E2>,
int> = 0>
1645 friend constexpr auto
1650 template <
typename E2, std::enable_if_t<detail::expected_equality_comparable_v<E, E2>,
int> = 0>
1651 friend constexpr auto
1654 return !(lhs == rhs);
1656 template <
typename E2, std::enable_if_t<detail::expected_equality_comparable_v<E, E2>,
int> = 0>
1657 friend constexpr auto
1660 return !(rhs == lhs);
1664 template <
typename Self,
typename F>
1665 static constexpr auto
1666 and_then_impl(Self&& self, F&& f)
1669 static_assert(is_expected_v<result_type> && std::is_same_v<typename result_type::error_type, E>);
1670 if (self.has_value())
1671 return result_type(std::invoke(std::forward<F>(f)));
1672 return result_type(
unexpect, std::forward<Self>(self).
error());
1674 template <
typename Self,
typename F>
1675 static constexpr auto
1676 or_else_impl(Self&& self, F&& f)
1679 static_assert(is_expected_v<result_type> && std::is_same_v<typename result_type::value_type, T>);
1680 if (self.has_value())
1681 return result_type();
1682 return result_type(std::invoke(std::forward<F>(f), std::forward<Self>(self).
error()));
1684 template <
typename Self,
typename F>
1685 static constexpr auto
1686 transform_impl(Self&& self, F&& f)
1688 using result_value = std::remove_cv_t<std::invoke_result_t<F>>;
1689 static_assert(valid_expected_value_v<result_value>);
1691 if (!self.has_value())
1692 return result_type(
unexpect, std::forward<Self>(self).
error());
1693 if constexpr (std::is_void_v<result_value>)
1695 std::invoke(std::forward<F>(f));
1696 return result_type();
1699 return result_type(expected_value_tag{}, expected_invoke_tag{}, std::forward<F>(f));
1701 template <
typename Self,
typename F>
1702 static constexpr auto
1703 transform_error_impl(Self&& self, F&& f)
1705 using result_error = std::remove_cv_t<std::invoke_result_t<F, decltype(std::forward<Self>(self).error())>>;
1708 if (self.has_value())
1709 return result_type();
1710 return result_type(expected_error_tag{}, expected_invoke_tag{}, std::forward<F>(f),
1711 std::forward<Self>(self).error());
1714 template <
typename,
typename>
1716 template <
typename,
typename>
1719 template <
typename F,
typename... Args>
1720 constexpr explicit expected_void(expected_error_tag, expected_invoke_tag, F&& f, Args&&... args)
1721 : storage_(
std::in_place,
std::in_place, expected_invoke_tag{},
std::forward<F>(f),
std::forward<Args>(args)...)
1725 template <
typename Source>
1726 static constexpr auto
1727 make_error_from(Source&& source) -> storage_type
1729 if (source.has_value())
1730 return std::nullopt;
1731 return storage_type(std::in_place, std::in_place, std::forward<Source>(source).
error());
1734 template <
typename G>
1736 assign_error(G&&
error)
1739 storage_->error = std::forward<G>(
error);
1741 storage_.emplace(std::in_place, std::forward<G>(
error));
1747 storage_.emplace(std::in_place, std::move(source.storage_->error));
1748 source.storage_.reset();
1751 storage_type storage_;
1756template <
typename E>
1763 using base::operator=;
1766template <
typename E>
1773 using base::operator=;
1776template <
typename E>
1783 using base::operator=;
1786template <
typename E>
1793 using base::operator=;
1797template <
typename T,
typename E,
typename T2,
1799 std::enable_if_t<detail::expected_equality_comparable_v<T, T2>,
int> = 0>
1803 if (!lhs.has_value())
1807template <
typename T,
typename E,
typename T2,
1809 std::enable_if_t<detail::expected_equality_comparable_v<T, T2>,
int> = 0>
1815template <
typename T,
typename E,
typename T2,
1817 std::enable_if_t<detail::expected_equality_comparable_v<T, T2>,
int> = 0>
1821 return !(lhs == rhs);
1823template <
typename T,
typename E,
typename T2,
1825 std::enable_if_t<detail::expected_equality_comparable_v<T, T2>,
int> = 0>
1829 return !(lhs == rhs);
1832template <
typename T,
typename E>
1841#undef THREADSCHEDULE_EXPECTED_EXCEPTION_CONSTEXPR
1842#undef THREADSCHEDULE_EXPECTED_THROW
constexpr auto has_error() const noexcept -> bool
constexpr auto or_else(F &&f) const &
constexpr auto operator=(unexpected< G > const &error) -> derived_type &
unexpected< E > unexpected_type
constexpr void value() &&
friend constexpr auto operator!=(derived_type const &lhs, unexpected< E2 > const &rhs) -> bool
constexpr expected_void(unexpect_t, Args &&... args)
constexpr void swap(derived_type &other) noexcept(std::is_nothrow_move_constructible_v< E > &&std::is_nothrow_swappable_v< E >)
friend constexpr auto operator!=(unexpected< E2 > const &lhs, derived_type const &rhs) -> bool
friend class expected_void
constexpr void emplace() noexcept
constexpr auto and_then(F &&f) &
constexpr auto transform_error(F &&f) &&
constexpr auto transform(F &&f) const &&
constexpr auto error() const &noexcept THREADSCHEDULE_LIFETIMEBOUND -> E const &
constexpr auto transform(F &&f) const &
constexpr void operator*() const noexcept
friend constexpr auto operator==(derived_type const &lhs, expected< T2, E2 > const &rhs) -> bool
constexpr expected_void(expected< U, G > &&source)
constexpr auto operator=(unexpected< G > &&error) -> derived_type &
constexpr auto error() &&noexcept THREADSCHEDULE_LIFETIMEBOUND -> E &&
constexpr auto error() &noexcept THREADSCHEDULE_LIFETIMEBOUND -> E &
constexpr auto and_then(F &&f) const &
constexpr auto and_then(F &&f) const &&
constexpr auto transform_error(F &&f) const &
friend constexpr auto operator!=(derived_type const &lhs, expected< T2, E2 > const &rhs) -> bool
constexpr auto transform_error(F &&f) &
constexpr auto error() const &&noexcept THREADSCHEDULE_LIFETIMEBOUND -> E const &&
friend constexpr auto operator==(unexpected< E2 > const &lhs, derived_type const &rhs) -> bool
constexpr expected_void(unexpected< G > &&source)
constexpr auto and_then(F &&f) &&
constexpr expected_void(unexpect_t, std::initializer_list< U > list, Args &&... args)
constexpr expected_void(unexpected< G > const &source)
constexpr auto transform(F &&f) &
constexpr auto or_else(F &&f) const &&
constexpr auto has_value() const noexcept -> bool
constexpr void value() const &
constexpr expected_void(expected< U, G > const &source)
constexpr auto transform_error(F &&f) const &&
constexpr auto error_or(G &&fallback) const &-> E
constexpr auto transform(F &&f) &&
constexpr expected_void() noexcept=default
constexpr auto error_or(G &&fallback) &&-> E
friend class threadschedule::expected
friend constexpr auto operator==(derived_type const &lhs, unexpected< E2 > const &rhs) -> bool
constexpr auto or_else(F &&f) &
constexpr auto or_else(F &&f) &&
constexpr auto error_or(G &&fallback) const &-> E
constexpr auto value() const &THREADSCHEDULE_LIFETIMEBOUND -> T const &
constexpr auto operator=(U &&value) -> expected &
constexpr auto operator->() const noexcept THREADSCHEDULE_LIFETIMEBOUND -> T const *
constexpr expected(expected< U, G > const &source)
constexpr expected(unexpect_t, Args &&... args)
constexpr expected(expected< U, G > &&source)
constexpr expected(unexpect_t, std::initializer_list< U > list, Args &&... args)
constexpr auto error() const &noexcept THREADSCHEDULE_LIFETIMEBOUND -> E const &
constexpr expected(unexpected< G > &&source)
constexpr auto error() const &&noexcept THREADSCHEDULE_LIFETIMEBOUND -> E const &&
constexpr auto operator*() const &noexcept THREADSCHEDULE_LIFETIMEBOUND -> T const &
constexpr auto operator*() &&noexcept THREADSCHEDULE_LIFETIMEBOUND -> T &&
unexpected< E > unexpected_type
constexpr auto value() &THREADSCHEDULE_LIFETIMEBOUND -> U &
constexpr auto value() const &&THREADSCHEDULE_LIFETIMEBOUND -> T const &&
constexpr auto value_or(U &&fallback) const &-> T
constexpr auto operator->() noexcept THREADSCHEDULE_LIFETIMEBOUND -> T *
constexpr auto error() &noexcept THREADSCHEDULE_LIFETIMEBOUND -> E &
friend constexpr auto operator!=(unexpected< E2 > const &lhs, expected const &rhs) -> bool
constexpr auto and_then(F &&f) &&
auto operator=(expected const &) -> expected &=default
constexpr expected(std::in_place_t, std::initializer_list< U > list, Args &&... args)
constexpr auto or_else(F &&f) &&
auto operator=(expected &&) -> expected &=default
constexpr auto transform(F &&f) &
constexpr auto has_error() const noexcept -> bool
constexpr auto error_or(G &&fallback) &&-> E
constexpr auto or_else(F &&f) const &
friend constexpr auto operator==(expected const &lhs, unexpected< E2 > const &rhs) -> bool
expected(expected const &)=default
constexpr auto operator=(unexpected< G > const &error) -> expected &
constexpr auto and_then(F &&f) &
constexpr auto transform_error(F &&f) &&
expected(expected &&)=default
friend constexpr auto operator!=(expected const &lhs, unexpected< E2 > const &rhs) -> bool
constexpr auto has_value() const noexcept -> bool
friend constexpr auto operator==(expected const &lhs, expected< T2, E2 > const &rhs) -> bool
constexpr auto emplace(std::initializer_list< U > list, Args &&... args) noexcept -> T &
friend constexpr auto operator!=(expected const &lhs, expected< T2, E2 > const &rhs) -> bool
constexpr auto and_then(F &&f) const &&
friend constexpr auto operator==(unexpected< E2 > const &lhs, expected const &rhs) -> bool
constexpr auto operator*() &noexcept THREADSCHEDULE_LIFETIMEBOUND -> T &
constexpr auto error() &&noexcept THREADSCHEDULE_LIFETIMEBOUND -> E &&
constexpr auto transform(F &&f) &&
constexpr auto transform(F &&f) const &
constexpr auto emplace(Args &&... args) noexcept -> T &
constexpr auto value_or(U &&fallback) &&-> T
constexpr void swap(expected &other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_constructible_v< E > &&std::is_nothrow_swappable_v< T > &&std::is_nothrow_swappable_v< E >)
constexpr expected(unexpected< G > const &source)
constexpr auto transform_error(F &&f) &
constexpr expected(std::in_place_t, Args &&... args)
constexpr auto or_else(F &&f) const &&
constexpr expected(U &&value)
constexpr auto operator*() const &&noexcept THREADSCHEDULE_LIFETIMEBOUND -> T const &&
constexpr auto transform_error(F &&f) const &
constexpr auto transform(F &&f) const &&
constexpr auto value() &&THREADSCHEDULE_LIFETIMEBOUND -> T &&
constexpr auto transform_error(F &&f) const &&
constexpr auto and_then(F &&f) const &
constexpr auto or_else(F &&f) &
unexpected(unexpected const &)=default
unexpected(unexpected &&)=default
constexpr auto error() const &&noexcept THREADSCHEDULE_LIFETIMEBOUND -> E const &&
constexpr auto error() const &noexcept THREADSCHEDULE_LIFETIMEBOUND -> E const &
friend constexpr void swap(unexpected &lhs, unexpected &rhs) noexcept(noexcept(lhs.swap(rhs)))
friend constexpr auto operator==(unexpected const &lhs, unexpected< G > const &rhs) -> bool
constexpr auto error() &&noexcept THREADSCHEDULE_LIFETIMEBOUND -> E &&
constexpr unexpected(std::in_place_t, Args &&... args)
auto operator=(unexpected const &) -> unexpected &=default
constexpr void swap(unexpected &other) noexcept(std::is_nothrow_swappable_v< E >)
constexpr unexpected(G &&error)
friend constexpr auto operator!=(unexpected const &lhs, unexpected< G > const &rhs) -> bool
auto operator=(unexpected &&) -> unexpected &=default
constexpr unexpected(std::in_place_t, std::initializer_list< U > list, Args &&... args)
constexpr auto error() &noexcept THREADSCHEDULE_LIFETIMEBOUND -> E &
#define THREADSCHEDULE_EXPECTED_EXCEPTION_CONSTEXPR
#define THREADSCHEDULE_EXPECTED_THROW(ex)
Optional compiler diagnostics for borrowed references and pointers.
#define THREADSCHEDULE_LIFETIMEBOUND
Aggregates multiple thread_registry_backend instances into a single queryable view.
constexpr bool is_unexpected_v
@ other
Standard round-robin time-sharing.
std::remove_cv_t< std::remove_reference_t< T > > expected_remove_cvref_t
constexpr bool valid_expected_error_v
constexpr unexpect_t unexpect
constexpr auto swap(expected< T, E > &lhs, expected< T, E > &rhs) noexcept(noexcept(lhs.swap(rhs))) -> decltype(lhs.swap(rhs))
constexpr auto operator!=(expected< T, E > const &lhs, T2 const &rhs) -> bool
unexpected(E) -> unexpected< E >
constexpr auto operator==(expected< T, E > const &lhs, T2 const &rhs) -> bool