29#ifndef _GLIBCXX_EXPECTED
30#define _GLIBCXX_EXPECTED
33#pragma GCC system_header
36#define __glibcxx_want_expected
37#define __glibcxx_want_freestanding_expected
38#define __glibcxx_want_constrained_equality
39#define __glibcxx_want_constexpr_exceptions
42#ifdef __cpp_lib_expected
49namespace std _GLIBCXX_VISIBILITY(default)
51_GLIBCXX_BEGIN_NAMESPACE_VERSION
64 template<
typename _Tp,
typename _Er>
71 template<
typename _Er>
78 template<
typename _Er>
79 class bad_expected_access;
81#if __cpp_lib_constexpr_exceptions >= 202502L
82#define _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS constexpr
84#define _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
88 class bad_expected_access<void> :
public exception
91 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS bad_expected_access() noexcept { }
92 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
93 bad_expected_access(
const bad_expected_access&)
noexcept =
default;
94 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
95 bad_expected_access(bad_expected_access&&) noexcept = default;
96 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
97 bad_expected_access& operator=(const bad_expected_access&) noexcept = default;
98 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
99 bad_expected_access& operator=(bad_expected_access&&) noexcept = default;
100 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
101 ~bad_expected_access() = default;
106 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS const
char*
107 what() const noexcept
override
108 {
return "bad access to std::expected without expected value"; }
111 template<
typename _Er>
112 class bad_expected_access :
public bad_expected_access<void> {
114 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
explicit
115 bad_expected_access(_Er __e) : _M_unex(std::move(__e)) { }
120 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS _Er&
125 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
const _Er&
126 error() const & noexcept
130 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS _Er&&
135 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
const _Er&&
136 error() const && noexcept
149 explicit unexpect_t() =
default;
156 inline constexpr unexpect_t unexpect{};
161 template<
typename _Tp>
162 constexpr bool __is_expected =
false;
163 template<
typename _Tp,
typename _Er>
164 constexpr bool __is_expected<expected<_Tp, _Er>> =
true;
166 template<
typename _Tp>
167 constexpr bool __is_unexpected =
false;
168 template<
typename _Tp>
169 constexpr bool __is_unexpected<unexpected<_Tp>> =
true;
171 template<
typename _Fn,
typename _Tp>
172 using __result = remove_cvref_t<invoke_result_t<_Fn&&, _Tp&&>>;
173 template<
typename _Fn,
typename _Tp>
174 using __result_xform = remove_cv_t<invoke_result_t<_Fn&&, _Tp&&>>;
175 template<
typename _Fn>
176 using __result0 = remove_cvref_t<invoke_result_t<_Fn&&>>;
177 template<
typename _Fn>
178 using __result0_xform = remove_cv_t<invoke_result_t<_Fn&&>>;
180 template<
typename _Er>
181 concept __can_be_unexpected
182 = is_object_v<_Er> && (!is_array_v<_Er>)
183 && (!__expected::__is_unexpected<_Er>)
184 && (!is_const_v<_Er>) && (!is_volatile_v<_Er>);
187 struct __in_place_inv { };
188 struct __unexpect_inv { };
192 template<
typename _Er>
195 static_assert( __expected::__can_be_unexpected<_Er> );
201 template<
typename _Err = _Er>
202 requires (!is_same_v<remove_cvref_t<_Err>,
unexpected>)
203 && (!is_same_v<remove_cvref_t<_Err>, in_place_t>)
204 && is_constructible_v<_Er, _Err>
207 noexcept(is_nothrow_constructible_v<_Er, _Err>)
208 : _M_unex(std::
forward<_Err>(__e))
211 template<
typename... _Args>
212 requires is_constructible_v<_Er, _Args...>
215 noexcept(is_nothrow_constructible_v<_Er, _Args...>)
216 : _M_unex(std::
forward<_Args>(__args)...)
219 template<
typename _Up,
typename... _Args>
220 requires is_constructible_v<_Er, initializer_list<_Up>&, _Args...>
222 unexpected(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
223 noexcept(is_nothrow_constructible_v<_Er, initializer_list<_Up>&,
225 : _M_unex(__il, std::
forward<_Args>(__args)...)
234 error() const & noexcept {
return _M_unex; }
238 error() &
noexcept {
return _M_unex; }
241 constexpr const _Er&&
242 error() const && noexcept {
return std::move(_M_unex); }
246 error() &&
noexcept {
return std::move(_M_unex); }
249 swap(
unexpected& __other)
noexcept(is_nothrow_swappable_v<_Er>)
250 requires is_swappable_v<_Er>
253 swap(_M_unex, __other._M_unex);
256 template<
typename _Err>
258 friend constexpr bool
260 {
return __x._M_unex == __y.error(); }
262 friend constexpr void
264 requires is_swappable_v<_Er>
276 template<
typename _Tp>
279 static_assert( is_nothrow_move_constructible_v<_Tp> );
283 : _M_guarded(__builtin_addressof(__x)), _M_tmp(std::move(__x))
284 { std::destroy_at(_M_guarded); }
289 if (_M_guarded) [[unlikely]]
290 std::construct_at(_M_guarded,
std::move(_M_tmp));
293 _Guard(
const _Guard&) =
delete;
294 _Guard& operator=(
const _Guard&) =
delete;
299 _M_guarded =
nullptr;
309 template<
typename _Tp,
typename _Up,
typename _Vp>
311 __reinit(_Tp* __newval, _Up* __oldval, _Vp&& __arg)
312 noexcept(is_nothrow_constructible_v<_Tp, _Vp>)
314 if constexpr (is_nothrow_constructible_v<_Tp, _Vp>)
316 std::destroy_at(__oldval);
319 else if constexpr (is_nothrow_move_constructible_v<_Tp>)
322 std::destroy_at(__oldval);
323 std::construct_at(__newval,
std::move(__tmp));
327 _Guard<_Up> __guard(*__oldval);
339 template<
typename _Tp,
typename _Up>
340 concept __not_constructing_bool_from_expected
341 = ! is_same_v<remove_cv_t<_Tp>,
bool>
342 || ! __is_expected<remove_cvref_t<_Up>>;
344 template<
typename _Tp,
typename _Up = remove_cvref_t<_Tp>>
345 concept __trivially_replaceable
346 = is_trivially_constructible_v<_Up, _Tp>
347 && is_trivially_assignable_v<_Up&, _Tp>
348 && is_trivially_destructible_v<_Up>;
350 template<
typename _Tp,
typename _Up = remove_cvref_t<_Tp>>
351 concept __usable_for_assign
352 = is_constructible_v<_Up, _Tp> && is_assignable_v<_Up&, _Tp>;
356 template<
typename _Tp>
357 concept __usable_for_trivial_assign
358 = __trivially_replaceable<_Tp> && __usable_for_assign<_Tp>;
362 template<
typename _Tp,
typename _Er>
363 concept __can_reassign_type
364 = is_nothrow_move_constructible_v<_Tp>
365 || is_nothrow_move_constructible_v<_Er>;
369 template<
typename _Tp,
typename _Er>
370 class [[nodiscard]] expected
372 static_assert( ! is_reference_v<_Tp> );
373 static_assert( ! is_function_v<_Tp> );
374 static_assert( ! is_same_v<remove_cv_t<_Tp>, in_place_t> );
375 static_assert( ! is_same_v<remove_cv_t<_Tp>, unexpect_t> );
376 static_assert( ! __expected::__is_unexpected<remove_cv_t<_Tp>> );
377 static_assert( __expected::__can_be_unexpected<_Er> );
381 template<
typename _Up,
typename _Gr,
typename _Unex = unexpected<_Er>,
382 typename = remove_cv_t<_Tp>>
383 static constexpr bool __cons_from_expected
384 = __or_v<is_constructible<_Tp, expected<_Up, _Gr>&>,
385 is_constructible<_Tp, expected<_Up, _Gr>>,
386 is_constructible<_Tp, const expected<_Up, _Gr>&>,
387 is_constructible<_Tp, const expected<_Up, _Gr>>,
388 is_convertible<expected<_Up, _Gr>&, _Tp>,
389 is_convertible<expected<_Up, _Gr>, _Tp>,
390 is_convertible<const expected<_Up, _Gr>&, _Tp>,
391 is_convertible<const expected<_Up, _Gr>, _Tp>,
392 is_constructible<_Unex, expected<_Up, _Gr>&>,
393 is_constructible<_Unex, expected<_Up, _Gr>>,
394 is_constructible<_Unex, const expected<_Up, _Gr>&>,
395 is_constructible<_Unex, const expected<_Up, _Gr>>
402 template<
typename _Up,
typename _Gr,
typename _Unex>
403 static constexpr bool __cons_from_expected<_Up, _Gr, _Unex, bool>
404 = __or_v<is_constructible<_Unex, expected<_Up, _Gr>&>,
405 is_constructible<_Unex, expected<_Up, _Gr>>,
406 is_constructible<_Unex, const expected<_Up, _Gr>&>,
407 is_constructible<_Unex, const expected<_Up, _Gr>>
410 template<
typename _Up,
typename _Gr>
411 constexpr static bool __explicit_conv
412 = __or_v<__not_<is_convertible<_Up, _Tp>>,
413 __not_<is_convertible<_Gr, _Er>>
416 template<
typename _Up>
417 static constexpr bool __same_val
418 = is_same_v<typename _Up::value_type, _Tp>;
420 template<
typename _Up>
421 static constexpr bool __same_err
422 = is_same_v<typename _Up::error_type, _Er>;
425 using value_type = _Tp;
427 using unexpected_type = unexpected<_Er>;
429 template<
typename _Up>
430 using rebind = expected<_Up, error_type>;
434 noexcept(is_nothrow_default_constructible_v<_Tp>)
435 requires is_default_constructible_v<_Tp>
436 : _M_val(), _M_has_value(true)
439 expected(
const expected&) =
default;
442 expected(
const expected& __x)
443 noexcept(__and_v<is_nothrow_copy_constructible<_Tp>,
444 is_nothrow_copy_constructible<_Er>>)
445 requires is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Er>
446 && (!is_trivially_copy_constructible_v<_Tp>
447 || !is_trivially_copy_constructible_v<_Er>)
448 : _M_has_value(__x._M_has_value)
451 std::construct_at(__builtin_addressof(_M_val), __x._M_val);
453 std::construct_at(__builtin_addressof(_M_unex), __x._M_unex);
456 expected(expected&&) =
default;
459 expected(expected&& __x)
460 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
461 is_nothrow_move_constructible<_Er>>)
462 requires is_move_constructible_v<_Tp> && is_move_constructible_v<_Er>
463 && (!is_trivially_move_constructible_v<_Tp>
464 || !is_trivially_move_constructible_v<_Er>)
465 : _M_has_value(__x._M_has_value)
468 std::construct_at(__builtin_addressof(_M_val),
471 std::construct_at(__builtin_addressof(_M_unex),
475 template<
typename _Up,
typename _Gr>
476 requires is_constructible_v<_Tp, const _Up&>
477 && is_constructible_v<_Er, const _Gr&>
478 && (!__cons_from_expected<_Up, _Gr>)
479 constexpr explicit(__explicit_conv<const _Up&, const _Gr&>)
480 expected(
const expected<_Up, _Gr>& __x)
481 noexcept(__and_v<is_nothrow_constructible<_Tp, const _Up&>,
482 is_nothrow_constructible<_Er, const _Gr&>>)
483 : _M_has_value(__x._M_has_value)
486 std::construct_at(__builtin_addressof(_M_val), __x._M_val);
488 std::construct_at(__builtin_addressof(_M_unex), __x._M_unex);
491 template<
typename _Up,
typename _Gr>
492 requires is_constructible_v<_Tp, _Up>
493 && is_constructible_v<_Er, _Gr>
494 && (!__cons_from_expected<_Up, _Gr>)
495 constexpr explicit(__explicit_conv<_Up, _Gr>)
496 expected(expected<_Up, _Gr>&& __x)
497 noexcept(__and_v<is_nothrow_constructible<_Tp, _Up>,
498 is_nothrow_constructible<_Er, _Gr>>)
499 : _M_has_value(__x._M_has_value)
502 std::construct_at(__builtin_addressof(_M_val),
505 std::construct_at(__builtin_addressof(_M_unex),
509 template<
typename _Up = remove_cv_t<_Tp>>
510 requires (!is_same_v<remove_cvref_t<_Up>, expected>)
511 && (!is_same_v<remove_cvref_t<_Up>, in_place_t>)
512 && (!is_same_v<remove_cvref_t<_Up>, unexpect_t>)
513 && is_constructible_v<_Tp, _Up>
514 && (!__expected::__is_unexpected<remove_cvref_t<_Up>>)
515 && __expected::__not_constructing_bool_from_expected<_Tp, _Up>
516 constexpr explicit(!is_convertible_v<_Up, _Tp>)
518 noexcept(is_nothrow_constructible_v<_Tp, _Up>)
519 : _M_val(std::
forward<_Up>(__v)), _M_has_value(true)
522 template<
typename _Gr = _Er>
523 requires is_constructible_v<_Er, const _Gr&>
524 constexpr explicit(!is_convertible_v<const _Gr&, _Er>)
525 expected(
const unexpected<_Gr>& __u)
526 noexcept(is_nothrow_constructible_v<_Er, const _Gr&>)
527 : _M_unex(__u.error()), _M_has_value(false)
530 template<
typename _Gr = _Er>
531 requires is_constructible_v<_Er, _Gr>
532 constexpr explicit(!is_convertible_v<_Gr, _Er>)
533 expected(unexpected<_Gr>&& __u)
534 noexcept(is_nothrow_constructible_v<_Er, _Gr>)
535 : _M_unex(std::move(__u).error()), _M_has_value(false)
538 template<
typename... _Args>
539 requires is_constructible_v<_Tp, _Args...>
541 expected(in_place_t, _Args&&... __args)
542 noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
543 : _M_val(std::
forward<_Args>(__args)...), _M_has_value(true)
546 template<
typename _Up,
typename... _Args>
547 requires is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>
549 expected(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
550 noexcept(is_nothrow_constructible_v<_Tp, initializer_list<_Up>&,
552 : _M_val(__il, std::
forward<_Args>(__args)...), _M_has_value(true)
555 template<
typename... _Args>
556 requires is_constructible_v<_Er, _Args...>
558 expected(unexpect_t, _Args&&... __args)
559 noexcept(is_nothrow_constructible_v<_Er, _Args...>)
560 : _M_unex(std::
forward<_Args>(__args)...), _M_has_value(false)
563 template<
typename _Up,
typename... _Args>
564 requires is_constructible_v<_Er, initializer_list<_Up>&, _Args...>
566 expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args)
567 noexcept(is_nothrow_constructible_v<_Er, initializer_list<_Up>&,
569 : _M_unex(__il, std::
forward<_Args>(__args)...), _M_has_value(false)
572 constexpr ~expected() =
default;
574 constexpr ~expected()
575 requires (!is_trivially_destructible_v<_Tp>)
576 || (!is_trivially_destructible_v<_Er>)
579 std::destroy_at(__builtin_addressof(_M_val));
581 std::destroy_at(__builtin_addressof(_M_unex));
587 expected& operator=(
const expected&) =
delete;
591 operator=(
const expected&)
592 noexcept(__and_v<is_nothrow_copy_constructible<_Tp>,
593 is_nothrow_copy_constructible<_Er>,
594 is_nothrow_copy_assignable<_Tp>,
595 is_nothrow_copy_assignable<_Er>>)
596 requires __expected::__usable_for_trivial_assign<const _Tp&>
597 && __expected::__usable_for_trivial_assign<const _Er&>
598 && __expected::__can_reassign_type<_Tp, _Er>
603 operator=(
const expected& __x)
604 noexcept(__and_v<is_nothrow_copy_constructible<_Tp>,
605 is_nothrow_copy_constructible<_Er>,
606 is_nothrow_copy_assignable<_Tp>,
607 is_nothrow_copy_assignable<_Er>>)
608 requires __expected::__usable_for_assign<const _Tp&>
609 && __expected::__usable_for_assign<const _Er&>
610 && __expected::__can_reassign_type<_Tp, _Er>
612 if (__x._M_has_value)
613 this->_M_assign_val(__x._M_val);
615 this->_M_assign_unex(__x._M_unex);
621 operator=(expected&&)
622 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
623 is_nothrow_move_constructible<_Er>,
624 is_nothrow_move_assignable<_Tp>,
625 is_nothrow_move_assignable<_Er>>)
626 requires __expected::__usable_for_trivial_assign<_Tp&&>
627 && __expected::__usable_for_trivial_assign<_Er&&>
628 && __expected::__can_reassign_type<_Tp, _Er>
633 operator=(expected&& __x)
634 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
635 is_nothrow_move_constructible<_Er>,
636 is_nothrow_move_assignable<_Tp>,
637 is_nothrow_move_assignable<_Er>>)
638 requires __expected::__usable_for_assign<_Tp&&>
639 && __expected::__usable_for_assign<_Er&&>
640 && __expected::__can_reassign_type<_Tp, _Er>
642 if (__x._M_has_value)
649 template<
typename _Up = remove_cv_t<_Tp>>
650 requires (!is_same_v<expected, remove_cvref_t<_Up>>)
651 && (!__expected::__is_unexpected<remove_cvref_t<_Up>>)
652 && is_constructible_v<_Tp, _Up> && is_assignable_v<_Tp&, _Up>
653 && (is_nothrow_constructible_v<_Tp, _Up>
654 || is_nothrow_move_constructible_v<_Tp>
655 || is_nothrow_move_constructible_v<_Er>)
663 template<
typename _Gr>
664 requires is_constructible_v<_Er, const _Gr&>
665 && is_assignable_v<_Er&, const _Gr&>
666 && (is_nothrow_constructible_v<_Er, const _Gr&>
667 || is_nothrow_move_constructible_v<_Tp>
668 || is_nothrow_move_constructible_v<_Er>)
670 operator=(
const unexpected<_Gr>& __e)
672 _M_assign_unex(__e.error());
676 template<
typename _Gr>
677 requires is_constructible_v<_Er, _Gr>
678 && is_assignable_v<_Er&, _Gr>
679 && (is_nothrow_constructible_v<_Er, _Gr>
680 || is_nothrow_move_constructible_v<_Tp>
681 || is_nothrow_move_constructible_v<_Er>)
683 operator=(unexpected<_Gr>&& __e)
691 template<
typename... _Args>
692 requires is_nothrow_constructible_v<_Tp, _Args...>
694 emplace(_Args&&... __args)
noexcept
697 std::destroy_at(__builtin_addressof(_M_val));
700 std::destroy_at(__builtin_addressof(_M_unex));
703 std::construct_at(__builtin_addressof(_M_val),
708 template<
typename _Up,
typename... _Args>
709 requires is_nothrow_constructible_v<_Tp, initializer_list<_Up>&,
712 emplace(initializer_list<_Up> __il, _Args&&... __args)
noexcept
715 std::destroy_at(__builtin_addressof(_M_val));
718 std::destroy_at(__builtin_addressof(_M_unex));
721 std::construct_at(__builtin_addressof(_M_val),
729 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
730 is_nothrow_move_constructible<_Er>,
731 is_nothrow_swappable<_Tp&>,
732 is_nothrow_swappable<_Er&>>)
733 requires is_swappable_v<_Tp> && is_swappable_v<_Er>
734 && is_move_constructible_v<_Tp>
735 && is_move_constructible_v<_Er>
736 && (is_nothrow_move_constructible_v<_Tp>
737 || is_nothrow_move_constructible_v<_Er>)
741 if (__x._M_has_value)
744 swap(_M_val, __x._M_val);
747 this->_M_swap_val_unex(__x);
751 if (__x._M_has_value)
752 __x._M_swap_val_unex(*
this);
756 swap(_M_unex, __x._M_unex);
765 operator->() const noexcept
767 __glibcxx_assert(_M_has_value);
768 return __builtin_addressof(_M_val);
773 operator->() noexcept
775 __glibcxx_assert(_M_has_value);
776 return __builtin_addressof(_M_val);
783 __glibcxx_assert(_M_has_value);
791 __glibcxx_assert(_M_has_value);
796 constexpr const _Tp&&
799 __glibcxx_assert(_M_has_value);
807 __glibcxx_assert(_M_has_value);
813 operator bool() const noexcept {
return _M_has_value; }
816 constexpr bool has_value() const noexcept {
return _M_has_value; }
821 static_assert( is_copy_constructible_v<_Er> );
822 if (_M_has_value) [[likely]]
824 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(_M_unex));
830 static_assert( is_copy_constructible_v<_Er> );
831 if (_M_has_value) [[likely]]
833 const auto& __unex = _M_unex;
834 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(__unex));
837 constexpr const _Tp&&
840 static_assert( is_copy_constructible_v<_Er> );
841 static_assert( is_constructible_v<_Er, const _Er&&> );
842 if (_M_has_value) [[likely]]
844 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(
std::move(_M_unex)));
850 static_assert( is_copy_constructible_v<_Er> );
851 static_assert( is_constructible_v<_Er, _Er&&> );
852 if (_M_has_value) [[likely]]
854 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(
std::move(_M_unex)));
858 error() const & noexcept
860 __glibcxx_assert(!_M_has_value);
867 __glibcxx_assert(!_M_has_value);
871 constexpr const _Er&&
872 error() const && noexcept
874 __glibcxx_assert(!_M_has_value);
881 __glibcxx_assert(!_M_has_value);
887 template<
typename _Up = remove_cv_t<_Tp>>
888 constexpr remove_cv_t<_Tp>
889 value_or(_Up&& __v)
const &
890 noexcept(__and_v<is_nothrow_copy_constructible<_Tp>,
891 is_nothrow_convertible<_Up, _Tp>>)
893 using _Xp = remove_cv_t<_Tp>;
894 static_assert( is_convertible_v<const _Tp&, _Xp> );
895 static_assert( is_convertible_v<_Up, _Tp> );
902 template<
typename _Up = remove_cv_t<_Tp>>
903 constexpr remove_cv_t<_Tp>
904 value_or(_Up&& __v) &&
905 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
906 is_nothrow_convertible<_Up, _Tp>>)
908 using _Xp = remove_cv_t<_Tp>;
909 static_assert( is_convertible_v<_Tp, _Xp> );
910 static_assert( is_convertible_v<_Up, _Xp> );
917 template<
typename _Gr = _Er>
919 error_or(_Gr&& __e)
const&
921 static_assert( is_copy_constructible_v<_Er> );
922 static_assert( is_convertible_v<_Gr, _Er> );
929 template<
typename _Gr = _Er>
931 error_or(_Gr&& __e) &&
933 static_assert( is_move_constructible_v<_Er> );
934 static_assert( is_convertible_v<_Gr, _Er> );
943 template<
typename _Fn>
requires is_constructible_v<_Er, _Er&>
945 and_then(_Fn&& __f) &
947 using _Up = __expected::__result<_Fn, _Tp&>;
948 static_assert(__expected::__is_expected<_Up>,
949 "the function passed to std::expected<T, E>::and_then "
950 "must return a std::expected");
951 static_assert(is_same_v<typename _Up::error_type, _Er>,
952 "the function passed to std::expected<T, E>::and_then "
953 "must return a std::expected with the same error_type");
958 return _Up(unexpect, _M_unex);
961 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er&>
963 and_then(_Fn&& __f)
const &
965 using _Up = __expected::__result<_Fn, const _Tp&>;
966 static_assert(__expected::__is_expected<_Up>,
967 "the function passed to std::expected<T, E>::and_then "
968 "must return a std::expected");
969 static_assert(is_same_v<typename _Up::error_type, _Er>,
970 "the function passed to std::expected<T, E>::and_then "
971 "must return a std::expected with the same error_type");
976 return _Up(unexpect, _M_unex);
979 template<
typename _Fn>
requires is_constructible_v<_Er, _Er>
981 and_then(_Fn&& __f) &&
983 using _Up = __expected::__result<_Fn, _Tp&&>;
984 static_assert(__expected::__is_expected<_Up>,
985 "the function passed to std::expected<T, E>::and_then "
986 "must return a std::expected");
987 static_assert(is_same_v<typename _Up::error_type, _Er>,
988 "the function passed to std::expected<T, E>::and_then "
989 "must return a std::expected with the same error_type");
994 return _Up(unexpect,
std::move(_M_unex));
998 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er>
1000 and_then(_Fn&& __f)
const &&
1002 using _Up = __expected::__result<_Fn, const _Tp&&>;
1003 static_assert(__expected::__is_expected<_Up>,
1004 "the function passed to std::expected<T, E>::and_then "
1005 "must return a std::expected");
1006 static_assert(is_same_v<typename _Up::error_type, _Er>,
1007 "the function passed to std::expected<T, E>::and_then "
1008 "must return a std::expected with the same error_type");
1013 return _Up(unexpect,
std::move(_M_unex));
1016 template<
typename _Fn>
requires is_constructible_v<_Tp, _Tp&>
1018 or_else(_Fn&& __f) &
1020 using _Gr = __expected::__result<_Fn, _Er&>;
1021 static_assert(__expected::__is_expected<_Gr>,
1022 "the function passed to std::expected<T, E>::or_else "
1023 "must return a std::expected");
1024 static_assert(is_same_v<typename _Gr::value_type, _Tp>,
1025 "the function passed to std::expected<T, E>::or_else "
1026 "must return a std::expected with the same value_type");
1029 return _Gr(in_place, _M_val);
1034 template<
typename _Fn>
requires is_constructible_v<_Tp, const _Tp&>
1036 or_else(_Fn&& __f)
const &
1038 using _Gr = __expected::__result<_Fn, const _Er&>;
1039 static_assert(__expected::__is_expected<_Gr>,
1040 "the function passed to std::expected<T, E>::or_else "
1041 "must return a std::expected");
1042 static_assert(is_same_v<typename _Gr::value_type, _Tp>,
1043 "the function passed to std::expected<T, E>::or_else "
1044 "must return a std::expected with the same value_type");
1047 return _Gr(in_place, _M_val);
1053 template<
typename _Fn>
requires is_constructible_v<_Tp, _Tp>
1055 or_else(_Fn&& __f) &&
1057 using _Gr = __expected::__result<_Fn, _Er&&>;
1058 static_assert(__expected::__is_expected<_Gr>,
1059 "the function passed to std::expected<T, E>::or_else "
1060 "must return a std::expected");
1061 static_assert(is_same_v<typename _Gr::value_type, _Tp>,
1062 "the function passed to std::expected<T, E>::or_else "
1063 "must return a std::expected with the same value_type");
1066 return _Gr(in_place,
std::move(_M_val));
1071 template<
typename _Fn>
requires is_constructible_v<_Tp, const _Tp>
1073 or_else(_Fn&& __f)
const &&
1075 using _Gr = __expected::__result<_Fn, const _Er&&>;
1076 static_assert(__expected::__is_expected<_Gr>,
1077 "the function passed to std::expected<T, E>::or_else "
1078 "must return a std::expected");
1079 static_assert(is_same_v<typename _Gr::value_type, _Tp>,
1080 "the function passed to std::expected<T, E>::or_else "
1081 "must return a std::expected with the same value_type");
1084 return _Gr(in_place,
std::move(_M_val));
1089 template<
typename _Fn>
requires is_constructible_v<_Er, _Er&>
1091 transform(_Fn&& __f) &
1093 using _Up = __expected::__result_xform<_Fn, _Tp&>;
1094 using _Res = expected<_Up, _Er>;
1097 return _Res(__in_place_inv{}, [&]() {
1102 return _Res(unexpect, _M_unex);
1105 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er&>
1107 transform(_Fn&& __f)
const &
1109 using _Up = __expected::__result_xform<_Fn, const _Tp&>;
1110 using _Res = expected<_Up, _Er>;
1113 return _Res(__in_place_inv{}, [&]() {
1118 return _Res(unexpect, _M_unex);
1121 template<
typename _Fn>
requires is_constructible_v<_Er, _Er>
1123 transform(_Fn&& __f) &&
1125 using _Up = __expected::__result_xform<_Fn, _Tp>;
1126 using _Res = expected<_Up, _Er>;
1129 return _Res(__in_place_inv{}, [&]() {
1134 return _Res(unexpect,
std::move(_M_unex));
1137 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er>
1139 transform(_Fn&& __f)
const &&
1141 using _Up = __expected::__result_xform<_Fn, const _Tp>;
1142 using _Res = expected<_Up, _Er>;
1145 return _Res(__in_place_inv{}, [&]() {
1150 return _Res(unexpect,
std::move(_M_unex));
1153 template<
typename _Fn>
requires is_constructible_v<_Tp, _Tp&>
1155 transform_error(_Fn&& __f) &
1157 using _Gr = __expected::__result_xform<_Fn, _Er&>;
1158 using _Res = expected<_Tp, _Gr>;
1161 return _Res(in_place, _M_val);
1163 return _Res(__unexpect_inv{}, [&]() {
1169 template<
typename _Fn>
requires is_constructible_v<_Tp, const _Tp&>
1171 transform_error(_Fn&& __f)
const &
1173 using _Gr = __expected::__result_xform<_Fn, const _Er&>;
1174 using _Res = expected<_Tp, _Gr>;
1177 return _Res(in_place, _M_val);
1179 return _Res(__unexpect_inv{}, [&]() {
1185 template<
typename _Fn>
requires is_constructible_v<_Tp, _Tp>
1187 transform_error(_Fn&& __f) &&
1189 using _Gr = __expected::__result_xform<_Fn, _Er&&>;
1190 using _Res = expected<_Tp, _Gr>;
1193 return _Res(in_place,
std::move(_M_val));
1195 return _Res(__unexpect_inv{}, [&]() {
1201 template<
typename _Fn>
requires is_constructible_v<_Tp, const _Tp>
1203 transform_error(_Fn&& __f)
const &&
1205 using _Gr = __expected::__result_xform<_Fn, const _Er&&>;
1206 using _Res = expected<_Tp, _Gr>;
1209 return _Res(in_place,
std::move(_M_val));
1211 return _Res(__unexpect_inv{}, [&]() {
1219 template<
typename _Up,
typename _Er2>
1220 requires (!is_void_v<_Up>)
1221 &&
requires (
const _Tp& __t,
const _Up& __u,
1222 const _Er& __e,
const _Er2& __e2) {
1223 { __t == __u } -> convertible_to<bool>;
1224 { __e == __e2 } -> convertible_to<bool>;
1227 friend constexpr bool
1228 operator==(
const expected& __x,
const expected<_Up, _Er2>& __y)
1229 noexcept(
noexcept(bool(*__x == *__y))
1230 &&
noexcept(bool(__x.error() == __y.error())))
1232 if (__x.has_value() != __y.has_value())
1234 if (__x.has_value())
1235 return *__x == *__y;
1236 return __x.error() == __y.error();
1239 template<
typename _Up, same_as<_Tp> _Vp>
1240 requires (!__expected::__is_expected<_Up>)
1241 &&
requires (
const _Tp& __t,
const _Up& __u) {
1242 { __t == __u } -> convertible_to<bool>;
1245 friend constexpr bool
1246 operator==(
const expected<_Vp, _Er>& __x,
const _Up& __v)
1247 noexcept(
noexcept(bool(*__x == __v)))
1249 if (__x.has_value())
1254 template<
typename _Er2>
1255 requires requires (
const _Er& __e,
const _Er2& __e2) {
1256 { __e == __e2 } -> convertible_to<bool>;
1259 friend constexpr bool
1260 operator==(
const expected& __x,
const unexpected<_Er2>& __e)
1261 noexcept(
noexcept(bool(__x.error() == __e.error())))
1263 if (!__x.has_value())
1264 return __x.error() == __e.error();
1268 friend constexpr void
1269 swap(expected& __x, expected& __y)
1270 noexcept(
noexcept(__x.swap(__y)))
1271 requires requires {__x.swap(__y);}
1275 template<
typename,
typename>
friend class expected;
1277 template<
typename _Vp>
1279 _M_assign_val(_Vp&& __v)
1285 __expected::__reinit(__builtin_addressof(_M_val),
1286 __builtin_addressof(_M_unex),
1288 _M_has_value =
true;
1292 template<
typename _Vp>
1294 _M_assign_unex(_Vp&& __v)
1298 __expected::__reinit(__builtin_addressof(_M_unex),
1299 __builtin_addressof(_M_val),
1301 _M_has_value =
false;
1310 _M_swap_val_unex(expected& __rhs)
1311 noexcept(__and_v<is_nothrow_move_constructible<_Er>,
1312 is_nothrow_move_constructible<_Tp>>)
1314 if constexpr (is_nothrow_move_constructible_v<_Er>)
1316 __expected::_Guard<_Er> __guard(__rhs._M_unex);
1317 std::construct_at(__builtin_addressof(__rhs._M_val),
1319 __rhs._M_has_value =
true;
1320 std::destroy_at(__builtin_addressof(_M_val));
1321 std::construct_at(__builtin_addressof(_M_unex),
1323 _M_has_value =
false;
1327 __expected::_Guard<_Tp> __guard(_M_val);
1328 std::construct_at(__builtin_addressof(_M_unex),
1330 _M_has_value =
false;
1331 std::destroy_at(__builtin_addressof(__rhs._M_unex));
1332 std::construct_at(__builtin_addressof(__rhs._M_val),
1334 __rhs._M_has_value =
true;
1338 using __in_place_inv = __expected::__in_place_inv;
1339 using __unexpect_inv = __expected::__unexpect_inv;
1341 template<
typename _Fn>
1343 expected(__in_place_inv, _Fn&& __fn)
1344 : _M_val(std::
forward<_Fn>(__fn)()), _M_has_value(true)
1347 template<
typename _Fn>
1349 expected(__unexpect_inv, _Fn&& __fn)
1350 : _M_unex(std::
forward<_Fn>(__fn)()), _M_has_value(false)
1354 remove_cv_t<_Tp> _M_val;
1362 template<
typename _Tp,
typename _Er>
requires is_void_v<_Tp>
1363 class [[nodiscard]] expected<_Tp, _Er>
1365 static_assert( __expected::__can_be_unexpected<_Er> );
1367 template<
typename _Up,
typename _Err,
typename _Unex = unexpected<_Er>>
1368 static constexpr bool __cons_from_expected
1369 = __or_v<is_constructible<_Unex, expected<_Up, _Err>&>,
1370 is_constructible<_Unex, expected<_Up, _Err>>,
1371 is_constructible<_Unex, const expected<_Up, _Err>&>,
1372 is_constructible<_Unex, const expected<_Up, _Err>>
1375 template<
typename _Up>
1376 static constexpr bool __same_val
1377 = is_same_v<typename _Up::value_type, _Tp>;
1379 template<
typename _Up>
1380 static constexpr bool __same_err
1381 = is_same_v<typename _Up::error_type, _Er>;
1384 using value_type = _Tp;
1386 using unexpected_type = unexpected<_Er>;
1388 template<
typename _Up>
1389 using rebind = expected<_Up, error_type>;
1393 : _M_void(), _M_has_value(true)
1396 expected(
const expected&) =
default;
1399 expected(
const expected& __x)
1400 noexcept(is_nothrow_copy_constructible_v<_Er>)
1401 requires is_copy_constructible_v<_Er>
1402 && (!is_trivially_copy_constructible_v<_Er>)
1403 : _M_void(), _M_has_value(__x._M_has_value)
1406 std::construct_at(__builtin_addressof(_M_unex), __x._M_unex);
1409 expected(expected&&) =
default;
1412 expected(expected&& __x)
1413 noexcept(is_nothrow_move_constructible_v<_Er>)
1414 requires is_move_constructible_v<_Er>
1415 && (!is_trivially_move_constructible_v<_Er>)
1416 : _M_void(), _M_has_value(__x._M_has_value)
1419 std::construct_at(__builtin_addressof(_M_unex),
1423 template<
typename _Up,
typename _Gr>
1424 requires is_void_v<_Up>
1425 && is_constructible_v<_Er, const _Gr&>
1426 && (!__cons_from_expected<_Up, _Gr>)
1427 constexpr explicit(!is_convertible_v<const _Gr&, _Er>)
1428 expected(
const expected<_Up, _Gr>& __x)
1429 noexcept(is_nothrow_constructible_v<_Er, const _Gr&>)
1430 : _M_void(), _M_has_value(__x._M_has_value)
1433 std::construct_at(__builtin_addressof(_M_unex), __x._M_unex);
1436 template<
typename _Up,
typename _Gr>
1437 requires is_void_v<_Up>
1438 && is_constructible_v<_Er, _Gr>
1439 && (!__cons_from_expected<_Up, _Gr>)
1440 constexpr explicit(!is_convertible_v<_Gr, _Er>)
1441 expected(expected<_Up, _Gr>&& __x)
1442 noexcept(is_nothrow_constructible_v<_Er, _Gr>)
1443 : _M_void(), _M_has_value(__x._M_has_value)
1446 std::construct_at(__builtin_addressof(_M_unex),
1450 template<
typename _Gr = _Er>
1451 requires is_constructible_v<_Er, const _Gr&>
1452 constexpr explicit(!is_convertible_v<const _Gr&, _Er>)
1453 expected(
const unexpected<_Gr>& __u)
1454 noexcept(is_nothrow_constructible_v<_Er, const _Gr&>)
1455 : _M_unex(__u.error()), _M_has_value(false)
1458 template<
typename _Gr = _Er>
1459 requires is_constructible_v<_Er, _Gr>
1460 constexpr explicit(!is_convertible_v<_Gr, _Er>)
1461 expected(unexpected<_Gr>&& __u)
1462 noexcept(is_nothrow_constructible_v<_Er, _Gr>)
1463 : _M_unex(std::move(__u).error()), _M_has_value(false)
1467 expected(in_place_t) noexcept
1471 template<
typename... _Args>
1472 requires is_constructible_v<_Er, _Args...>
1474 expected(unexpect_t, _Args&&... __args)
1475 noexcept(is_nothrow_constructible_v<_Er, _Args...>)
1476 : _M_unex(std::
forward<_Args>(__args)...), _M_has_value(false)
1479 template<
typename _Up,
typename... _Args>
1480 requires is_constructible_v<_Er, initializer_list<_Up>&, _Args...>
1482 expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args)
1483 noexcept(is_nothrow_constructible_v<_Er, initializer_list<_Up>&,
1485 : _M_unex(__il, std::
forward<_Args>(__args)...), _M_has_value(false)
1488 constexpr ~expected() =
default;
1490 constexpr ~expected()
requires (!is_trivially_destructible_v<_Er>)
1493 std::destroy_at(__builtin_addressof(_M_unex));
1499 expected& operator=(
const expected&) =
delete;
1503 operator=(
const expected&)
1504 noexcept(__and_v<is_nothrow_copy_constructible<_Er>,
1505 is_nothrow_copy_assignable<_Er>>)
1506 requires __expected::__usable_for_trivial_assign<const _Er&>
1511 operator=(
const expected& __x)
1512 noexcept(__and_v<is_nothrow_copy_constructible<_Er>,
1513 is_nothrow_copy_assignable<_Er>>)
1514 requires __expected::__usable_for_assign<const _Er&>
1516 if (__x._M_has_value)
1519 _M_assign_unex(__x._M_unex);
1525 operator=(expected&&)
1526 noexcept(__and_v<is_nothrow_move_constructible<_Er>,
1527 is_nothrow_move_assignable<_Er>>)
1528 requires __expected::__usable_for_trivial_assign<_Er&&>
1533 operator=(expected&& __x)
1534 noexcept(__and_v<is_nothrow_move_constructible<_Er>,
1535 is_nothrow_move_assignable<_Er>>)
1536 requires __expected::__usable_for_assign<_Er&&>
1538 if (__x._M_has_value)
1545 template<
typename _Gr>
1546 requires is_constructible_v<_Er, const _Gr&>
1547 && is_assignable_v<_Er&, const _Gr&>
1549 operator=(
const unexpected<_Gr>& __e)
1551 _M_assign_unex(__e.error());
1555 template<
typename _Gr>
1556 requires is_constructible_v<_Er, _Gr>
1557 && is_assignable_v<_Er&, _Gr>
1559 operator=(unexpected<_Gr>&& __e)
1572 std::destroy_at(__builtin_addressof(_M_unex));
1573 _M_has_value =
true;
1580 noexcept(__and_v<is_nothrow_swappable<_Er&>,
1581 is_nothrow_move_constructible<_Er>>)
1582 requires is_swappable_v<_Er> && is_move_constructible_v<_Er>
1586 if (!__x._M_has_value)
1588 std::construct_at(__builtin_addressof(_M_unex),
1590 std::destroy_at(__builtin_addressof(__x._M_unex));
1591 _M_has_value =
false;
1592 __x._M_has_value =
true;
1597 if (__x._M_has_value)
1599 std::construct_at(__builtin_addressof(__x._M_unex),
1601 std::destroy_at(__builtin_addressof(_M_unex));
1602 _M_has_value =
true;
1603 __x._M_has_value =
false;
1608 swap(_M_unex, __x._M_unex);
1617 operator bool() const noexcept {
return _M_has_value; }
1620 constexpr bool has_value() const noexcept {
return _M_has_value; }
1623 operator*() const noexcept { __glibcxx_assert(_M_has_value); }
1628 static_assert( is_copy_constructible_v<_Er> );
1629 if (_M_has_value) [[likely]]
1631 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(_M_unex));
1637 static_assert( is_copy_constructible_v<_Er> );
1638 static_assert( is_move_constructible_v<_Er> );
1639 if (_M_has_value) [[likely]]
1641 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(
std::move(_M_unex)));
1644 constexpr const _Er&
1645 error() const & noexcept
1647 __glibcxx_assert(!_M_has_value);
1654 __glibcxx_assert(!_M_has_value);
1658 constexpr const _Er&&
1659 error() const && noexcept
1661 __glibcxx_assert(!_M_has_value);
1668 __glibcxx_assert(!_M_has_value);
1672 template<
typename _Gr = _Er>
1674 error_or(_Gr&& __e)
const&
1676 static_assert( is_copy_constructible_v<_Er> );
1677 static_assert( is_convertible_v<_Gr, _Er> );
1684 template<
typename _Gr = _Er>
1686 error_or(_Gr&& __e) &&
1688 static_assert( is_move_constructible_v<_Er> );
1689 static_assert( is_convertible_v<_Gr, _Er> );
1698 template<
typename _Fn>
requires is_constructible_v<_Er, _Er&>
1700 and_then(_Fn&& __f) &
1702 using _Up = __expected::__result0<_Fn>;
1703 static_assert(__expected::__is_expected<_Up>);
1704 static_assert(is_same_v<typename _Up::error_type, _Er>);
1709 return _Up(unexpect, _M_unex);
1712 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er&>
1714 and_then(_Fn&& __f)
const &
1716 using _Up = __expected::__result0<_Fn>;
1717 static_assert(__expected::__is_expected<_Up>);
1718 static_assert(is_same_v<typename _Up::error_type, _Er>);
1723 return _Up(unexpect, _M_unex);
1726 template<
typename _Fn>
requires is_constructible_v<_Er, _Er>
1728 and_then(_Fn&& __f) &&
1730 using _Up = __expected::__result0<_Fn>;
1731 static_assert(__expected::__is_expected<_Up>);
1732 static_assert(is_same_v<typename _Up::error_type, _Er>);
1737 return _Up(unexpect,
std::move(_M_unex));
1740 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er>
1742 and_then(_Fn&& __f)
const &&
1744 using _Up = __expected::__result0<_Fn>;
1745 static_assert(__expected::__is_expected<_Up>);
1746 static_assert(is_same_v<typename _Up::error_type, _Er>);
1751 return _Up(unexpect,
std::move(_M_unex));
1754 template<
typename _Fn>
1756 or_else(_Fn&& __f) &
1758 using _Gr = __expected::__result<_Fn, _Er&>;
1759 static_assert(__expected::__is_expected<_Gr>);
1760 static_assert(is_same_v<typename _Gr::value_type, _Tp>);
1768 template<
typename _Fn>
1770 or_else(_Fn&& __f)
const &
1772 using _Gr = __expected::__result<_Fn, const _Er&>;
1773 static_assert(__expected::__is_expected<_Gr>);
1774 static_assert(is_same_v<typename _Gr::value_type, _Tp>);
1782 template<
typename _Fn>
1784 or_else(_Fn&& __f) &&
1786 using _Gr = __expected::__result<_Fn, _Er&&>;
1787 static_assert(__expected::__is_expected<_Gr>);
1788 static_assert(is_same_v<typename _Gr::value_type, _Tp>);
1796 template<
typename _Fn>
1798 or_else(_Fn&& __f)
const &&
1800 using _Gr = __expected::__result<_Fn, const _Er&&>;
1801 static_assert(__expected::__is_expected<_Gr>);
1802 static_assert(is_same_v<typename _Gr::value_type, _Tp>);
1810 template<
typename _Fn>
requires is_constructible_v<_Er, _Er&>
1812 transform(_Fn&& __f) &
1814 using _Up = __expected::__result0_xform<_Fn>;
1815 using _Res = expected<_Up, _Er>;
1820 return _Res(unexpect, _M_unex);
1823 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er&>
1825 transform(_Fn&& __f)
const &
1827 using _Up = __expected::__result0_xform<_Fn>;
1828 using _Res = expected<_Up, _Er>;
1833 return _Res(unexpect, _M_unex);
1836 template<
typename _Fn>
requires is_constructible_v<_Er, _Er>
1838 transform(_Fn&& __f) &&
1840 using _Up = __expected::__result0_xform<_Fn>;
1841 using _Res = expected<_Up, _Er>;
1846 return _Res(unexpect,
std::move(_M_unex));
1849 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er>
1851 transform(_Fn&& __f)
const &&
1853 using _Up = __expected::__result0_xform<_Fn>;
1854 using _Res = expected<_Up, _Er>;
1859 return _Res(unexpect,
std::move(_M_unex));
1862 template<
typename _Fn>
1864 transform_error(_Fn&& __f) &
1866 using _Gr = __expected::__result_xform<_Fn, _Er&>;
1867 using _Res = expected<_Tp, _Gr>;
1872 return _Res(__unexpect_inv{}, [&]() {
1878 template<
typename _Fn>
1880 transform_error(_Fn&& __f)
const &
1882 using _Gr = __expected::__result_xform<_Fn, const _Er&>;
1883 using _Res = expected<_Tp, _Gr>;
1888 return _Res(__unexpect_inv{}, [&]() {
1894 template<
typename _Fn>
1896 transform_error(_Fn&& __f) &&
1898 using _Gr = __expected::__result_xform<_Fn, _Er&&>;
1899 using _Res = expected<_Tp, _Gr>;
1904 return _Res(__unexpect_inv{}, [&]() {
1910 template<
typename _Fn>
1912 transform_error(_Fn&& __f)
const &&
1914 using _Gr = __expected::__result_xform<_Fn, const _Er&&>;
1915 using _Res = expected<_Tp, _Gr>;
1920 return _Res(__unexpect_inv{}, [&]() {
1928 template<
typename _Up,
typename _Er2>
1929 requires is_void_v<_Up>
1930 &&
requires (
const _Er& __e,
const _Er2& __e2) {
1931 { __e == __e2 } -> convertible_to<bool>;
1934 friend constexpr bool
1935 operator==(
const expected& __x,
const expected<_Up, _Er2>& __y)
1936 noexcept(
noexcept(bool(__x.error() == __y.error())))
1938 if (__x.has_value() != __y.has_value())
1940 if (__x.has_value())
1942 return __x.error() == __y.error();
1945 template<
typename _Er2>
1946 requires requires (
const _Er& __e,
const _Er2& __e2) {
1947 { __e == __e2 } -> convertible_to<bool>;
1950 friend constexpr bool
1951 operator==(
const expected& __x,
const unexpected<_Er2>& __e)
1952 noexcept(
noexcept(bool(__x.error() == __e.error())))
1954 if (!__x.has_value())
1955 return __x.error() == __e.error();
1959 friend constexpr void
1960 swap(expected& __x, expected& __y)
1961 noexcept(
noexcept(__x.swap(__y)))
1962 requires requires { __x.swap(__y); }
1966 template<
typename,
typename>
friend class expected;
1968 template<
typename _Vp>
1970 _M_assign_unex(_Vp&& __v)
1974 std::construct_at(__builtin_addressof(_M_unex),
1976 _M_has_value =
false;
1982 using __in_place_inv = __expected::__in_place_inv;
1983 using __unexpect_inv = __expected::__unexpect_inv;
1985 template<
typename _Fn>
1987 expected(__in_place_inv, _Fn&& __fn)
1988 : _M_void(), _M_has_value(true)
1991 template<
typename _Fn>
1993 expected(__unexpect_inv, _Fn&& __fn)
1994 : _M_unex(std::
forward<_Fn>(__fn)()), _M_has_value(false)
2006_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
Base class for all library exceptions.