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
40#define __glibcxx_want_hardened_expected
43#ifdef __cpp_lib_expected
50namespace std _GLIBCXX_VISIBILITY(default)
52_GLIBCXX_BEGIN_NAMESPACE_VERSION
65 template<
typename _Tp,
typename _Er>
72 template<
typename _Er>
79 template<
typename _Er>
80 class bad_expected_access;
82#if __cpp_lib_constexpr_exceptions >= 202502L
83#define _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS constexpr
85#define _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
89 class bad_expected_access<void> :
public exception
92 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS bad_expected_access() noexcept { }
93 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
94 bad_expected_access(
const bad_expected_access&)
noexcept =
default;
95 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
96 bad_expected_access(bad_expected_access&&) noexcept = default;
97 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
98 bad_expected_access& operator=(const bad_expected_access&) noexcept = default;
99 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
100 bad_expected_access& operator=(bad_expected_access&&) noexcept = default;
101 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
102 ~bad_expected_access() = default;
107 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS const
char*
108 what() const noexcept
override
109 {
return "bad access to std::expected without expected value"; }
112 template<
typename _Er>
113 class bad_expected_access :
public bad_expected_access<void> {
115 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
explicit
116 bad_expected_access(_Er __e) : _M_unex(std::move(__e)) { }
121 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS _Er&
126 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
const _Er&
127 error() const & noexcept
131 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS _Er&&
136 _GLIBCXX_CONSTEXPR_BAD_EXPECTED_ACCESS
const _Er&&
137 error() const && noexcept
150 explicit unexpect_t() =
default;
157 inline constexpr unexpect_t unexpect{};
162 template<
typename _Tp>
163 constexpr bool __is_expected =
false;
164 template<
typename _Tp,
typename _Er>
165 constexpr bool __is_expected<expected<_Tp, _Er>> =
true;
167 template<
typename _Tp>
168 constexpr bool __is_unexpected =
false;
169 template<
typename _Tp>
170 constexpr bool __is_unexpected<unexpected<_Tp>> =
true;
172 template<
typename _Fn,
typename _Tp>
173 using __result = remove_cvref_t<invoke_result_t<_Fn&&, _Tp&&>>;
174 template<
typename _Fn,
typename _Tp>
175 using __result_xform = remove_cv_t<invoke_result_t<_Fn&&, _Tp&&>>;
176 template<
typename _Fn>
177 using __result0 = remove_cvref_t<invoke_result_t<_Fn&&>>;
178 template<
typename _Fn>
179 using __result0_xform = remove_cv_t<invoke_result_t<_Fn&&>>;
181 template<
typename _Er>
182 concept __can_be_unexpected
183 = is_object_v<_Er> && (!is_array_v<_Er>)
184 && (!__expected::__is_unexpected<_Er>)
185 && (!is_const_v<_Er>) && (!is_volatile_v<_Er>);
188 struct __in_place_inv { };
189 struct __unexpect_inv { };
193 template<
typename _Er>
196 static_assert( __expected::__can_be_unexpected<_Er> );
199 constexpr unexpected(
const unexpected&) =
default;
200 constexpr unexpected(unexpected&&) =
default;
202 template<
typename _Err = _Er>
203 requires (!is_same_v<remove_cvref_t<_Err>, unexpected>)
204 && (!is_same_v<remove_cvref_t<_Err>, in_place_t>)
205 && is_constructible_v<_Er, _Err>
207 unexpected(_Err&& __e)
208 noexcept(is_nothrow_constructible_v<_Er, _Err>)
209 : _M_unex(std::
forward<_Err>(__e))
212 template<
typename... _Args>
213 requires is_constructible_v<_Er, _Args...>
215 unexpected(in_place_t, _Args&&... __args)
216 noexcept(is_nothrow_constructible_v<_Er, _Args...>)
217 : _M_unex(std::
forward<_Args>(__args)...)
220 template<
typename _Up,
typename... _Args>
221 requires is_constructible_v<_Er, initializer_list<_Up>&, _Args...>
223 unexpected(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
224 noexcept(is_nothrow_constructible_v<_Er, initializer_list<_Up>&,
226 : _M_unex(__il, std::
forward<_Args>(__args)...)
229 constexpr unexpected& operator=(
const unexpected&) =
default;
230 constexpr unexpected& operator=(unexpected&&) =
default;
235 error() const & noexcept {
return _M_unex; }
239 error() &
noexcept {
return _M_unex; }
242 constexpr const _Er&&
243 error() const && noexcept {
return std::move(_M_unex); }
247 error() &&
noexcept {
return std::move(_M_unex); }
250 swap(unexpected& __other)
noexcept(is_nothrow_swappable_v<_Er>)
251 requires is_swappable_v<_Er>
254 swap(_M_unex, __other._M_unex);
257 template<
typename _Err>
259 friend constexpr bool
260 operator==(
const unexpected& __x,
const unexpected<_Err>& __y)
261 {
return __x._M_unex == __y.error(); }
263 friend constexpr void
264 swap(unexpected& __x, unexpected& __y)
noexcept(
noexcept(__x.swap(__y)))
265 requires is_swappable_v<_Er>
272 template<
typename _Er> unexpected(_Er) -> unexpected<_Er>;
277 template<
typename _Tp>
280 static_assert( is_nothrow_move_constructible_v<_Tp> );
284 : _M_guarded(__builtin_addressof(__x)), _M_tmp(std::move(__x))
285 { std::destroy_at(_M_guarded); }
290 if (_M_guarded) [[unlikely]]
291 std::construct_at(_M_guarded,
std::move(_M_tmp));
294 _Guard(
const _Guard&) =
delete;
295 _Guard& operator=(
const _Guard&) =
delete;
300 _M_guarded =
nullptr;
310 template<
typename _Tp,
typename _Up,
typename _Vp>
312 __reinit(_Tp* __newval, _Up* __oldval, _Vp&& __arg)
313 noexcept(is_nothrow_constructible_v<_Tp, _Vp>)
315 if constexpr (is_nothrow_constructible_v<_Tp, _Vp>)
317 std::destroy_at(__oldval);
320 else if constexpr (is_nothrow_move_constructible_v<_Tp>)
323 std::destroy_at(__oldval);
324 std::construct_at(__newval,
std::move(__tmp));
328 _Guard<_Up> __guard(*__oldval);
340 template<
typename _Tp,
typename _Up>
341 concept __not_constructing_bool_from_expected
342 = ! is_same_v<remove_cv_t<_Tp>,
bool>
343 || ! __is_expected<remove_cvref_t<_Up>>;
345 template<
typename _Tp,
typename _Up = remove_cvref_t<_Tp>>
346 concept __trivially_replaceable
347 = is_trivially_constructible_v<_Up, _Tp>
348 && is_trivially_assignable_v<_Up&, _Tp>
349 && is_trivially_destructible_v<_Up>;
351 template<
typename _Tp,
typename _Up = remove_cvref_t<_Tp>>
352 concept __usable_for_assign
353 = is_constructible_v<_Up, _Tp> && is_assignable_v<_Up&, _Tp>;
357 template<
typename _Tp>
358 concept __usable_for_trivial_assign
359 = __trivially_replaceable<_Tp> && __usable_for_assign<_Tp>;
363 template<
typename _Tp,
typename _Er>
364 concept __can_reassign_type
365 = is_nothrow_move_constructible_v<_Tp>
366 || is_nothrow_move_constructible_v<_Er>;
370 template<
typename _Tp,
typename _Er>
371 class [[nodiscard]] expected
373 static_assert( ! is_reference_v<_Tp> );
374 static_assert( ! is_function_v<_Tp> );
375 static_assert( ! is_same_v<remove_cv_t<_Tp>, in_place_t> );
376 static_assert( ! is_same_v<remove_cv_t<_Tp>, unexpect_t> );
377 static_assert( ! __expected::__is_unexpected<remove_cv_t<_Tp>> );
378 static_assert( __expected::__can_be_unexpected<_Er> );
382 template<
typename _Up,
typename _Gr,
typename _Unex = unexpected<_Er>,
383 typename = remove_cv_t<_Tp>>
384 static constexpr bool __cons_from_expected
385 = __or_v<is_constructible<_Tp, expected<_Up, _Gr>&>,
386 is_constructible<_Tp, expected<_Up, _Gr>>,
387 is_constructible<_Tp, const expected<_Up, _Gr>&>,
388 is_constructible<_Tp, const expected<_Up, _Gr>>,
389 is_convertible<expected<_Up, _Gr>&, _Tp>,
390 is_convertible<expected<_Up, _Gr>, _Tp>,
391 is_convertible<const expected<_Up, _Gr>&, _Tp>,
392 is_convertible<const expected<_Up, _Gr>, _Tp>,
393 is_constructible<_Unex, expected<_Up, _Gr>&>,
394 is_constructible<_Unex, expected<_Up, _Gr>>,
395 is_constructible<_Unex, const expected<_Up, _Gr>&>,
396 is_constructible<_Unex, const expected<_Up, _Gr>>
403 template<
typename _Up,
typename _Gr,
typename _Unex>
404 static constexpr bool __cons_from_expected<_Up, _Gr, _Unex, bool>
405 = __or_v<is_constructible<_Unex, expected<_Up, _Gr>&>,
406 is_constructible<_Unex, expected<_Up, _Gr>>,
407 is_constructible<_Unex, const expected<_Up, _Gr>&>,
408 is_constructible<_Unex, const expected<_Up, _Gr>>
411 template<
typename _Up,
typename _Gr>
412 constexpr static bool __explicit_conv
413 = __or_v<__not_<is_convertible<_Up, _Tp>>,
414 __not_<is_convertible<_Gr, _Er>>
417 template<
typename _Up>
418 static constexpr bool __same_val
419 = is_same_v<typename _Up::value_type, _Tp>;
421 template<
typename _Up>
422 static constexpr bool __same_err
423 = is_same_v<typename _Up::error_type, _Er>;
426 using value_type = _Tp;
428 using unexpected_type = unexpected<_Er>;
430 template<
typename _Up>
431 using rebind = expected<_Up, error_type>;
435 noexcept(is_nothrow_default_constructible_v<_Tp>)
436 requires is_default_constructible_v<_Tp>
437 : _M_val(), _M_has_value(true)
440 expected(
const expected&) =
default;
443 expected(
const expected& __x)
444 noexcept(__and_v<is_nothrow_copy_constructible<_Tp>,
445 is_nothrow_copy_constructible<_Er>>)
446 requires is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Er>
447 && (!is_trivially_copy_constructible_v<_Tp>
448 || !is_trivially_copy_constructible_v<_Er>)
449 : _M_has_value(__x._M_has_value)
452 std::construct_at(__builtin_addressof(_M_val), __x._M_val);
454 std::construct_at(__builtin_addressof(_M_unex), __x._M_unex);
457 expected(expected&&) =
default;
460 expected(expected&& __x)
461 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
462 is_nothrow_move_constructible<_Er>>)
463 requires is_move_constructible_v<_Tp> && is_move_constructible_v<_Er>
464 && (!is_trivially_move_constructible_v<_Tp>
465 || !is_trivially_move_constructible_v<_Er>)
466 : _M_has_value(__x._M_has_value)
469 std::construct_at(__builtin_addressof(_M_val),
472 std::construct_at(__builtin_addressof(_M_unex),
476 template<
typename _Up,
typename _Gr>
477 requires is_constructible_v<_Tp, const _Up&>
478 && is_constructible_v<_Er, const _Gr&>
479 && (!__cons_from_expected<_Up, _Gr>)
480 constexpr explicit(__explicit_conv<const _Up&, const _Gr&>)
481 expected(
const expected<_Up, _Gr>& __x)
482 noexcept(__and_v<is_nothrow_constructible<_Tp, const _Up&>,
483 is_nothrow_constructible<_Er, const _Gr&>>)
484 : _M_has_value(__x._M_has_value)
487 std::construct_at(__builtin_addressof(_M_val), __x._M_val);
489 std::construct_at(__builtin_addressof(_M_unex), __x._M_unex);
492 template<
typename _Up,
typename _Gr>
493 requires is_constructible_v<_Tp, _Up>
494 && is_constructible_v<_Er, _Gr>
495 && (!__cons_from_expected<_Up, _Gr>)
496 constexpr explicit(__explicit_conv<_Up, _Gr>)
497 expected(expected<_Up, _Gr>&& __x)
498 noexcept(__and_v<is_nothrow_constructible<_Tp, _Up>,
499 is_nothrow_constructible<_Er, _Gr>>)
500 : _M_has_value(__x._M_has_value)
503 std::construct_at(__builtin_addressof(_M_val),
506 std::construct_at(__builtin_addressof(_M_unex),
510 template<
typename _Up = remove_cv_t<_Tp>>
511 requires (!is_same_v<remove_cvref_t<_Up>, expected>)
512 && (!is_same_v<remove_cvref_t<_Up>, in_place_t>)
513 && (!is_same_v<remove_cvref_t<_Up>, unexpect_t>)
514 && is_constructible_v<_Tp, _Up>
515 && (!__expected::__is_unexpected<remove_cvref_t<_Up>>)
516 && __expected::__not_constructing_bool_from_expected<_Tp, _Up>
517 constexpr explicit(!is_convertible_v<_Up, _Tp>)
519 noexcept(is_nothrow_constructible_v<_Tp, _Up>)
520 : _M_val(std::
forward<_Up>(__v)), _M_has_value(true)
523 template<
typename _Gr = _Er>
524 requires is_constructible_v<_Er, const _Gr&>
525 constexpr explicit(!is_convertible_v<const _Gr&, _Er>)
526 expected(
const unexpected<_Gr>& __u)
527 noexcept(is_nothrow_constructible_v<_Er, const _Gr&>)
528 : _M_unex(__u.error()), _M_has_value(false)
531 template<
typename _Gr = _Er>
532 requires is_constructible_v<_Er, _Gr>
533 constexpr explicit(!is_convertible_v<_Gr, _Er>)
534 expected(unexpected<_Gr>&& __u)
535 noexcept(is_nothrow_constructible_v<_Er, _Gr>)
536 : _M_unex(std::move(__u).error()), _M_has_value(false)
539 template<
typename... _Args>
540 requires is_constructible_v<_Tp, _Args...>
542 expected(in_place_t, _Args&&... __args)
543 noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
544 : _M_val(std::
forward<_Args>(__args)...), _M_has_value(true)
547 template<
typename _Up,
typename... _Args>
548 requires is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>
550 expected(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
551 noexcept(is_nothrow_constructible_v<_Tp, initializer_list<_Up>&,
553 : _M_val(__il, std::
forward<_Args>(__args)...), _M_has_value(true)
556 template<
typename... _Args>
557 requires is_constructible_v<_Er, _Args...>
559 expected(unexpect_t, _Args&&... __args)
560 noexcept(is_nothrow_constructible_v<_Er, _Args...>)
561 : _M_unex(std::
forward<_Args>(__args)...), _M_has_value(false)
564 template<
typename _Up,
typename... _Args>
565 requires is_constructible_v<_Er, initializer_list<_Up>&, _Args...>
567 expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args)
568 noexcept(is_nothrow_constructible_v<_Er, initializer_list<_Up>&,
570 : _M_unex(__il, std::
forward<_Args>(__args)...), _M_has_value(false)
573 constexpr ~expected() =
default;
575 constexpr ~expected()
576 requires (!is_trivially_destructible_v<_Tp>)
577 || (!is_trivially_destructible_v<_Er>)
580 std::destroy_at(__builtin_addressof(_M_val));
582 std::destroy_at(__builtin_addressof(_M_unex));
588 expected& operator=(
const expected&) =
delete;
592 operator=(
const expected&)
593 noexcept(__and_v<is_nothrow_copy_constructible<_Tp>,
594 is_nothrow_copy_constructible<_Er>,
595 is_nothrow_copy_assignable<_Tp>,
596 is_nothrow_copy_assignable<_Er>>)
597 requires __expected::__usable_for_trivial_assign<const _Tp&>
598 && __expected::__usable_for_trivial_assign<const _Er&>
599 && __expected::__can_reassign_type<_Tp, _Er>
604 operator=(
const expected& __x)
605 noexcept(__and_v<is_nothrow_copy_constructible<_Tp>,
606 is_nothrow_copy_constructible<_Er>,
607 is_nothrow_copy_assignable<_Tp>,
608 is_nothrow_copy_assignable<_Er>>)
609 requires __expected::__usable_for_assign<const _Tp&>
610 && __expected::__usable_for_assign<const _Er&>
611 && __expected::__can_reassign_type<_Tp, _Er>
613 if (__x._M_has_value)
614 this->_M_assign_val(__x._M_val);
616 this->_M_assign_unex(__x._M_unex);
622 operator=(expected&&)
623 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
624 is_nothrow_move_constructible<_Er>,
625 is_nothrow_move_assignable<_Tp>,
626 is_nothrow_move_assignable<_Er>>)
627 requires __expected::__usable_for_trivial_assign<_Tp&&>
628 && __expected::__usable_for_trivial_assign<_Er&&>
629 && __expected::__can_reassign_type<_Tp, _Er>
634 operator=(expected&& __x)
635 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
636 is_nothrow_move_constructible<_Er>,
637 is_nothrow_move_assignable<_Tp>,
638 is_nothrow_move_assignable<_Er>>)
639 requires __expected::__usable_for_assign<_Tp&&>
640 && __expected::__usable_for_assign<_Er&&>
641 && __expected::__can_reassign_type<_Tp, _Er>
643 if (__x._M_has_value)
650 template<
typename _Up = remove_cv_t<_Tp>>
651 requires (!is_same_v<expected, remove_cvref_t<_Up>>)
652 && (!__expected::__is_unexpected<remove_cvref_t<_Up>>)
653 && is_constructible_v<_Tp, _Up> && is_assignable_v<_Tp&, _Up>
654 && (is_nothrow_constructible_v<_Tp, _Up>
655 || is_nothrow_move_constructible_v<_Tp>
656 || is_nothrow_move_constructible_v<_Er>)
664 template<
typename _Gr>
665 requires is_constructible_v<_Er, const _Gr&>
666 && is_assignable_v<_Er&, const _Gr&>
667 && (is_nothrow_constructible_v<_Er, const _Gr&>
668 || is_nothrow_move_constructible_v<_Tp>
669 || is_nothrow_move_constructible_v<_Er>)
671 operator=(
const unexpected<_Gr>& __e)
673 _M_assign_unex(__e.error());
677 template<
typename _Gr>
678 requires is_constructible_v<_Er, _Gr>
679 && is_assignable_v<_Er&, _Gr>
680 && (is_nothrow_constructible_v<_Er, _Gr>
681 || is_nothrow_move_constructible_v<_Tp>
682 || is_nothrow_move_constructible_v<_Er>)
684 operator=(unexpected<_Gr>&& __e)
692 template<
typename... _Args>
693 requires is_nothrow_constructible_v<_Tp, _Args...>
695 emplace(_Args&&... __args)
noexcept
698 std::destroy_at(__builtin_addressof(_M_val));
701 std::destroy_at(__builtin_addressof(_M_unex));
704 std::construct_at(__builtin_addressof(_M_val),
709 template<
typename _Up,
typename... _Args>
710 requires is_nothrow_constructible_v<_Tp, initializer_list<_Up>&,
713 emplace(initializer_list<_Up> __il, _Args&&... __args)
noexcept
716 std::destroy_at(__builtin_addressof(_M_val));
719 std::destroy_at(__builtin_addressof(_M_unex));
722 std::construct_at(__builtin_addressof(_M_val),
730 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
731 is_nothrow_move_constructible<_Er>,
732 is_nothrow_swappable<_Tp&>,
733 is_nothrow_swappable<_Er&>>)
734 requires is_swappable_v<_Tp> && is_swappable_v<_Er>
735 && is_move_constructible_v<_Tp>
736 && is_move_constructible_v<_Er>
737 && (is_nothrow_move_constructible_v<_Tp>
738 || is_nothrow_move_constructible_v<_Er>)
742 if (__x._M_has_value)
745 swap(_M_val, __x._M_val);
748 this->_M_swap_val_unex(__x);
752 if (__x._M_has_value)
753 __x._M_swap_val_unex(*
this);
757 swap(_M_unex, __x._M_unex);
766 operator->() const noexcept
768 __glibcxx_assert(_M_has_value);
769 return __builtin_addressof(_M_val);
774 operator->() noexcept
776 __glibcxx_assert(_M_has_value);
777 return __builtin_addressof(_M_val);
784 __glibcxx_assert(_M_has_value);
792 __glibcxx_assert(_M_has_value);
797 constexpr const _Tp&&
800 __glibcxx_assert(_M_has_value);
808 __glibcxx_assert(_M_has_value);
814 operator bool() const noexcept {
return _M_has_value; }
817 constexpr bool has_value() const noexcept {
return _M_has_value; }
822 static_assert( is_copy_constructible_v<_Er> );
823 if (_M_has_value) [[likely]]
825 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(_M_unex));
831 static_assert( is_copy_constructible_v<_Er> );
832 if (_M_has_value) [[likely]]
834 const auto& __unex = _M_unex;
835 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(__unex));
838 constexpr const _Tp&&
841 static_assert( is_copy_constructible_v<_Er> );
842 static_assert( is_constructible_v<_Er, const _Er&&> );
843 if (_M_has_value) [[likely]]
845 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(
std::move(_M_unex)));
851 static_assert( is_copy_constructible_v<_Er> );
852 static_assert( is_constructible_v<_Er, _Er&&> );
853 if (_M_has_value) [[likely]]
855 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(
std::move(_M_unex)));
859 error() const & noexcept
861 __glibcxx_assert(!_M_has_value);
868 __glibcxx_assert(!_M_has_value);
872 constexpr const _Er&&
873 error() const && noexcept
875 __glibcxx_assert(!_M_has_value);
882 __glibcxx_assert(!_M_has_value);
888 template<
typename _Up = remove_cv_t<_Tp>>
889 constexpr remove_cv_t<_Tp>
890 value_or(_Up&& __v)
const &
891 noexcept(__and_v<is_nothrow_copy_constructible<_Tp>,
892 is_nothrow_convertible<_Up, _Tp>>)
894 using _Xp = remove_cv_t<_Tp>;
895 static_assert( is_convertible_v<const _Tp&, _Xp> );
896 static_assert( is_convertible_v<_Up, _Tp> );
903 template<
typename _Up = remove_cv_t<_Tp>>
904 constexpr remove_cv_t<_Tp>
905 value_or(_Up&& __v) &&
906 noexcept(__and_v<is_nothrow_move_constructible<_Tp>,
907 is_nothrow_convertible<_Up, _Tp>>)
909 using _Xp = remove_cv_t<_Tp>;
910 static_assert( is_convertible_v<_Tp, _Xp> );
911 static_assert( is_convertible_v<_Up, _Xp> );
918 template<
typename _Gr = _Er>
920 error_or(_Gr&& __e)
const&
922 static_assert( is_copy_constructible_v<_Er> );
923 static_assert( is_convertible_v<_Gr, _Er> );
930 template<
typename _Gr = _Er>
932 error_or(_Gr&& __e) &&
934 static_assert( is_move_constructible_v<_Er> );
935 static_assert( is_convertible_v<_Gr, _Er> );
944 template<
typename _Fn>
requires is_constructible_v<_Er, _Er&>
946 and_then(_Fn&& __f) &
948 using _Up = __expected::__result<_Fn, _Tp&>;
949 static_assert(__expected::__is_expected<_Up>,
950 "the function passed to std::expected<T, E>::and_then "
951 "must return a std::expected");
952 static_assert(is_same_v<typename _Up::error_type, _Er>,
953 "the function passed to std::expected<T, E>::and_then "
954 "must return a std::expected with the same error_type");
959 return _Up(unexpect, _M_unex);
962 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er&>
964 and_then(_Fn&& __f)
const &
966 using _Up = __expected::__result<_Fn, const _Tp&>;
967 static_assert(__expected::__is_expected<_Up>,
968 "the function passed to std::expected<T, E>::and_then "
969 "must return a std::expected");
970 static_assert(is_same_v<typename _Up::error_type, _Er>,
971 "the function passed to std::expected<T, E>::and_then "
972 "must return a std::expected with the same error_type");
977 return _Up(unexpect, _M_unex);
980 template<
typename _Fn>
requires is_constructible_v<_Er, _Er>
982 and_then(_Fn&& __f) &&
984 using _Up = __expected::__result<_Fn, _Tp&&>;
985 static_assert(__expected::__is_expected<_Up>,
986 "the function passed to std::expected<T, E>::and_then "
987 "must return a std::expected");
988 static_assert(is_same_v<typename _Up::error_type, _Er>,
989 "the function passed to std::expected<T, E>::and_then "
990 "must return a std::expected with the same error_type");
995 return _Up(unexpect,
std::move(_M_unex));
999 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er>
1001 and_then(_Fn&& __f)
const &&
1003 using _Up = __expected::__result<_Fn, const _Tp&&>;
1004 static_assert(__expected::__is_expected<_Up>,
1005 "the function passed to std::expected<T, E>::and_then "
1006 "must return a std::expected");
1007 static_assert(is_same_v<typename _Up::error_type, _Er>,
1008 "the function passed to std::expected<T, E>::and_then "
1009 "must return a std::expected with the same error_type");
1014 return _Up(unexpect,
std::move(_M_unex));
1017 template<
typename _Fn>
requires is_constructible_v<_Tp, _Tp&>
1019 or_else(_Fn&& __f) &
1021 using _Gr = __expected::__result<_Fn, _Er&>;
1022 static_assert(__expected::__is_expected<_Gr>,
1023 "the function passed to std::expected<T, E>::or_else "
1024 "must return a std::expected");
1025 static_assert(is_same_v<typename _Gr::value_type, _Tp>,
1026 "the function passed to std::expected<T, E>::or_else "
1027 "must return a std::expected with the same value_type");
1030 return _Gr(in_place, _M_val);
1035 template<
typename _Fn>
requires is_constructible_v<_Tp, const _Tp&>
1037 or_else(_Fn&& __f)
const &
1039 using _Gr = __expected::__result<_Fn, const _Er&>;
1040 static_assert(__expected::__is_expected<_Gr>,
1041 "the function passed to std::expected<T, E>::or_else "
1042 "must return a std::expected");
1043 static_assert(is_same_v<typename _Gr::value_type, _Tp>,
1044 "the function passed to std::expected<T, E>::or_else "
1045 "must return a std::expected with the same value_type");
1048 return _Gr(in_place, _M_val);
1054 template<
typename _Fn>
requires is_constructible_v<_Tp, _Tp>
1056 or_else(_Fn&& __f) &&
1058 using _Gr = __expected::__result<_Fn, _Er&&>;
1059 static_assert(__expected::__is_expected<_Gr>,
1060 "the function passed to std::expected<T, E>::or_else "
1061 "must return a std::expected");
1062 static_assert(is_same_v<typename _Gr::value_type, _Tp>,
1063 "the function passed to std::expected<T, E>::or_else "
1064 "must return a std::expected with the same value_type");
1067 return _Gr(in_place,
std::move(_M_val));
1072 template<
typename _Fn>
requires is_constructible_v<_Tp, const _Tp>
1074 or_else(_Fn&& __f)
const &&
1076 using _Gr = __expected::__result<_Fn, const _Er&&>;
1077 static_assert(__expected::__is_expected<_Gr>,
1078 "the function passed to std::expected<T, E>::or_else "
1079 "must return a std::expected");
1080 static_assert(is_same_v<typename _Gr::value_type, _Tp>,
1081 "the function passed to std::expected<T, E>::or_else "
1082 "must return a std::expected with the same value_type");
1085 return _Gr(in_place,
std::move(_M_val));
1090 template<
typename _Fn>
requires is_constructible_v<_Er, _Er&>
1092 transform(_Fn&& __f) &
1094 using _Up = __expected::__result_xform<_Fn, _Tp&>;
1095 using _Res = expected<_Up, _Er>;
1098 return _Res(__in_place_inv{}, [&]() {
1103 return _Res(unexpect, _M_unex);
1106 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er&>
1108 transform(_Fn&& __f)
const &
1110 using _Up = __expected::__result_xform<_Fn, const _Tp&>;
1111 using _Res = expected<_Up, _Er>;
1114 return _Res(__in_place_inv{}, [&]() {
1119 return _Res(unexpect, _M_unex);
1122 template<
typename _Fn>
requires is_constructible_v<_Er, _Er>
1124 transform(_Fn&& __f) &&
1126 using _Up = __expected::__result_xform<_Fn, _Tp>;
1127 using _Res = expected<_Up, _Er>;
1130 return _Res(__in_place_inv{}, [&]() {
1135 return _Res(unexpect,
std::move(_M_unex));
1138 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er>
1140 transform(_Fn&& __f)
const &&
1142 using _Up = __expected::__result_xform<_Fn, const _Tp>;
1143 using _Res = expected<_Up, _Er>;
1146 return _Res(__in_place_inv{}, [&]() {
1151 return _Res(unexpect,
std::move(_M_unex));
1154 template<
typename _Fn>
requires is_constructible_v<_Tp, _Tp&>
1156 transform_error(_Fn&& __f) &
1158 using _Gr = __expected::__result_xform<_Fn, _Er&>;
1159 using _Res = expected<_Tp, _Gr>;
1162 return _Res(in_place, _M_val);
1164 return _Res(__unexpect_inv{}, [&]() {
1170 template<
typename _Fn>
requires is_constructible_v<_Tp, const _Tp&>
1172 transform_error(_Fn&& __f)
const &
1174 using _Gr = __expected::__result_xform<_Fn, const _Er&>;
1175 using _Res = expected<_Tp, _Gr>;
1178 return _Res(in_place, _M_val);
1180 return _Res(__unexpect_inv{}, [&]() {
1186 template<
typename _Fn>
requires is_constructible_v<_Tp, _Tp>
1188 transform_error(_Fn&& __f) &&
1190 using _Gr = __expected::__result_xform<_Fn, _Er&&>;
1191 using _Res = expected<_Tp, _Gr>;
1194 return _Res(in_place,
std::move(_M_val));
1196 return _Res(__unexpect_inv{}, [&]() {
1202 template<
typename _Fn>
requires is_constructible_v<_Tp, const _Tp>
1204 transform_error(_Fn&& __f)
const &&
1206 using _Gr = __expected::__result_xform<_Fn, const _Er&&>;
1207 using _Res = expected<_Tp, _Gr>;
1210 return _Res(in_place,
std::move(_M_val));
1212 return _Res(__unexpect_inv{}, [&]() {
1220 template<
typename _Up,
typename _Er2>
1221 requires (!is_void_v<_Up>)
1222 &&
requires (
const _Tp& __t,
const _Up& __u,
1223 const _Er& __e,
const _Er2& __e2) {
1224 { __t == __u } -> convertible_to<bool>;
1225 { __e == __e2 } -> convertible_to<bool>;
1228 friend constexpr bool
1229 operator==(
const expected& __x,
const expected<_Up, _Er2>& __y)
1230 noexcept(
noexcept(bool(*__x == *__y))
1231 &&
noexcept(bool(__x.error() == __y.error())))
1233 if (__x.has_value() != __y.has_value())
1235 if (__x.has_value())
1236 return *__x == *__y;
1237 return __x.error() == __y.error();
1240 template<
typename _Up, same_as<_Tp> _Vp>
1241 requires (!__expected::__is_expected<_Up>)
1242 &&
requires (
const _Tp& __t,
const _Up& __u) {
1243 { __t == __u } -> convertible_to<bool>;
1246 friend constexpr bool
1247 operator==(
const expected<_Vp, _Er>& __x,
const _Up& __v)
1248 noexcept(
noexcept(bool(*__x == __v)))
1250 if (__x.has_value())
1255 template<
typename _Er2>
1256 requires requires (
const _Er& __e,
const _Er2& __e2) {
1257 { __e == __e2 } -> convertible_to<bool>;
1260 friend constexpr bool
1261 operator==(
const expected& __x,
const unexpected<_Er2>& __e)
1262 noexcept(
noexcept(bool(__x.error() == __e.error())))
1264 if (!__x.has_value())
1265 return __x.error() == __e.error();
1269 friend constexpr void
1270 swap(expected& __x, expected& __y)
1271 noexcept(
noexcept(__x.swap(__y)))
1272 requires requires {__x.swap(__y);}
1276 template<
typename,
typename>
friend class expected;
1278 template<
typename _Vp>
1280 _M_assign_val(_Vp&& __v)
1286 __expected::__reinit(__builtin_addressof(_M_val),
1287 __builtin_addressof(_M_unex),
1289 _M_has_value =
true;
1293 template<
typename _Vp>
1295 _M_assign_unex(_Vp&& __v)
1299 __expected::__reinit(__builtin_addressof(_M_unex),
1300 __builtin_addressof(_M_val),
1302 _M_has_value =
false;
1311 _M_swap_val_unex(expected& __rhs)
1312 noexcept(__and_v<is_nothrow_move_constructible<_Er>,
1313 is_nothrow_move_constructible<_Tp>>)
1315 if constexpr (is_nothrow_move_constructible_v<_Er>)
1317 __expected::_Guard<_Er> __guard(__rhs._M_unex);
1318 std::construct_at(__builtin_addressof(__rhs._M_val),
1320 __rhs._M_has_value =
true;
1321 std::destroy_at(__builtin_addressof(_M_val));
1322 std::construct_at(__builtin_addressof(_M_unex),
1324 _M_has_value =
false;
1328 __expected::_Guard<_Tp> __guard(_M_val);
1329 std::construct_at(__builtin_addressof(_M_unex),
1331 _M_has_value =
false;
1332 std::destroy_at(__builtin_addressof(__rhs._M_unex));
1333 std::construct_at(__builtin_addressof(__rhs._M_val),
1335 __rhs._M_has_value =
true;
1339 using __in_place_inv = __expected::__in_place_inv;
1340 using __unexpect_inv = __expected::__unexpect_inv;
1342 template<
typename _Fn>
1344 expected(__in_place_inv, _Fn&& __fn)
1345 : _M_val(std::
forward<_Fn>(__fn)()), _M_has_value(true)
1348 template<
typename _Fn>
1350 expected(__unexpect_inv, _Fn&& __fn)
1351 : _M_unex(std::
forward<_Fn>(__fn)()), _M_has_value(false)
1355 remove_cv_t<_Tp> _M_val;
1363 template<
typename _Tp,
typename _Er>
requires is_void_v<_Tp>
1364 class [[nodiscard]] expected<_Tp, _Er>
1366 static_assert( __expected::__can_be_unexpected<_Er> );
1368 template<
typename _Up,
typename _Err,
typename _Unex = unexpected<_Er>>
1369 static constexpr bool __cons_from_expected
1370 = __or_v<is_constructible<_Unex, expected<_Up, _Err>&>,
1371 is_constructible<_Unex, expected<_Up, _Err>>,
1372 is_constructible<_Unex, const expected<_Up, _Err>&>,
1373 is_constructible<_Unex, const expected<_Up, _Err>>
1376 template<
typename _Up>
1377 static constexpr bool __same_val
1378 = is_same_v<typename _Up::value_type, _Tp>;
1380 template<
typename _Up>
1381 static constexpr bool __same_err
1382 = is_same_v<typename _Up::error_type, _Er>;
1385 using value_type = _Tp;
1387 using unexpected_type = unexpected<_Er>;
1389 template<
typename _Up>
1390 using rebind = expected<_Up, error_type>;
1394 : _M_void(), _M_has_value(true)
1397 expected(
const expected&) =
default;
1400 expected(
const expected& __x)
1401 noexcept(is_nothrow_copy_constructible_v<_Er>)
1402 requires is_copy_constructible_v<_Er>
1403 && (!is_trivially_copy_constructible_v<_Er>)
1404 : _M_void(), _M_has_value(__x._M_has_value)
1407 std::construct_at(__builtin_addressof(_M_unex), __x._M_unex);
1410 expected(expected&&) =
default;
1413 expected(expected&& __x)
1414 noexcept(is_nothrow_move_constructible_v<_Er>)
1415 requires is_move_constructible_v<_Er>
1416 && (!is_trivially_move_constructible_v<_Er>)
1417 : _M_void(), _M_has_value(__x._M_has_value)
1420 std::construct_at(__builtin_addressof(_M_unex),
1424 template<
typename _Up,
typename _Gr>
1425 requires is_void_v<_Up>
1426 && is_constructible_v<_Er, const _Gr&>
1427 && (!__cons_from_expected<_Up, _Gr>)
1428 constexpr explicit(!is_convertible_v<const _Gr&, _Er>)
1429 expected(
const expected<_Up, _Gr>& __x)
1430 noexcept(is_nothrow_constructible_v<_Er, const _Gr&>)
1431 : _M_void(), _M_has_value(__x._M_has_value)
1434 std::construct_at(__builtin_addressof(_M_unex), __x._M_unex);
1437 template<
typename _Up,
typename _Gr>
1438 requires is_void_v<_Up>
1439 && is_constructible_v<_Er, _Gr>
1440 && (!__cons_from_expected<_Up, _Gr>)
1441 constexpr explicit(!is_convertible_v<_Gr, _Er>)
1442 expected(expected<_Up, _Gr>&& __x)
1443 noexcept(is_nothrow_constructible_v<_Er, _Gr>)
1444 : _M_void(), _M_has_value(__x._M_has_value)
1447 std::construct_at(__builtin_addressof(_M_unex),
1451 template<
typename _Gr = _Er>
1452 requires is_constructible_v<_Er, const _Gr&>
1453 constexpr explicit(!is_convertible_v<const _Gr&, _Er>)
1454 expected(
const unexpected<_Gr>& __u)
1455 noexcept(is_nothrow_constructible_v<_Er, const _Gr&>)
1456 : _M_unex(__u.error()), _M_has_value(false)
1459 template<
typename _Gr = _Er>
1460 requires is_constructible_v<_Er, _Gr>
1461 constexpr explicit(!is_convertible_v<_Gr, _Er>)
1462 expected(unexpected<_Gr>&& __u)
1463 noexcept(is_nothrow_constructible_v<_Er, _Gr>)
1464 : _M_unex(std::move(__u).error()), _M_has_value(false)
1468 expected(in_place_t) noexcept
1472 template<
typename... _Args>
1473 requires is_constructible_v<_Er, _Args...>
1475 expected(unexpect_t, _Args&&... __args)
1476 noexcept(is_nothrow_constructible_v<_Er, _Args...>)
1477 : _M_unex(std::
forward<_Args>(__args)...), _M_has_value(false)
1480 template<
typename _Up,
typename... _Args>
1481 requires is_constructible_v<_Er, initializer_list<_Up>&, _Args...>
1483 expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args)
1484 noexcept(is_nothrow_constructible_v<_Er, initializer_list<_Up>&,
1486 : _M_unex(__il, std::
forward<_Args>(__args)...), _M_has_value(false)
1489 constexpr ~expected() =
default;
1491 constexpr ~expected()
requires (!is_trivially_destructible_v<_Er>)
1494 std::destroy_at(__builtin_addressof(_M_unex));
1500 expected& operator=(
const expected&) =
delete;
1504 operator=(
const expected&)
1505 noexcept(__and_v<is_nothrow_copy_constructible<_Er>,
1506 is_nothrow_copy_assignable<_Er>>)
1507 requires __expected::__usable_for_trivial_assign<const _Er&>
1512 operator=(
const expected& __x)
1513 noexcept(__and_v<is_nothrow_copy_constructible<_Er>,
1514 is_nothrow_copy_assignable<_Er>>)
1515 requires __expected::__usable_for_assign<const _Er&>
1517 if (__x._M_has_value)
1520 _M_assign_unex(__x._M_unex);
1526 operator=(expected&&)
1527 noexcept(__and_v<is_nothrow_move_constructible<_Er>,
1528 is_nothrow_move_assignable<_Er>>)
1529 requires __expected::__usable_for_trivial_assign<_Er&&>
1534 operator=(expected&& __x)
1535 noexcept(__and_v<is_nothrow_move_constructible<_Er>,
1536 is_nothrow_move_assignable<_Er>>)
1537 requires __expected::__usable_for_assign<_Er&&>
1539 if (__x._M_has_value)
1546 template<
typename _Gr>
1547 requires is_constructible_v<_Er, const _Gr&>
1548 && is_assignable_v<_Er&, const _Gr&>
1550 operator=(
const unexpected<_Gr>& __e)
1552 _M_assign_unex(__e.error());
1556 template<
typename _Gr>
1557 requires is_constructible_v<_Er, _Gr>
1558 && is_assignable_v<_Er&, _Gr>
1560 operator=(unexpected<_Gr>&& __e)
1573 std::destroy_at(__builtin_addressof(_M_unex));
1574 _M_has_value =
true;
1581 noexcept(__and_v<is_nothrow_swappable<_Er&>,
1582 is_nothrow_move_constructible<_Er>>)
1583 requires is_swappable_v<_Er> && is_move_constructible_v<_Er>
1587 if (!__x._M_has_value)
1589 std::construct_at(__builtin_addressof(_M_unex),
1591 std::destroy_at(__builtin_addressof(__x._M_unex));
1592 _M_has_value =
false;
1593 __x._M_has_value =
true;
1598 if (__x._M_has_value)
1600 std::construct_at(__builtin_addressof(__x._M_unex),
1602 std::destroy_at(__builtin_addressof(_M_unex));
1603 _M_has_value =
true;
1604 __x._M_has_value =
false;
1609 swap(_M_unex, __x._M_unex);
1618 operator bool() const noexcept {
return _M_has_value; }
1621 constexpr bool has_value() const noexcept {
return _M_has_value; }
1624 operator*() const noexcept { __glibcxx_assert(_M_has_value); }
1629 static_assert( is_copy_constructible_v<_Er> );
1630 if (_M_has_value) [[likely]]
1632 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(_M_unex));
1638 static_assert( is_copy_constructible_v<_Er> );
1639 static_assert( is_move_constructible_v<_Er> );
1640 if (_M_has_value) [[likely]]
1642 _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(
std::move(_M_unex)));
1645 constexpr const _Er&
1646 error() const & noexcept
1648 __glibcxx_assert(!_M_has_value);
1655 __glibcxx_assert(!_M_has_value);
1659 constexpr const _Er&&
1660 error() const && noexcept
1662 __glibcxx_assert(!_M_has_value);
1669 __glibcxx_assert(!_M_has_value);
1673 template<
typename _Gr = _Er>
1675 error_or(_Gr&& __e)
const&
1677 static_assert( is_copy_constructible_v<_Er> );
1678 static_assert( is_convertible_v<_Gr, _Er> );
1685 template<
typename _Gr = _Er>
1687 error_or(_Gr&& __e) &&
1689 static_assert( is_move_constructible_v<_Er> );
1690 static_assert( is_convertible_v<_Gr, _Er> );
1699 template<
typename _Fn>
requires is_constructible_v<_Er, _Er&>
1701 and_then(_Fn&& __f) &
1703 using _Up = __expected::__result0<_Fn>;
1704 static_assert(__expected::__is_expected<_Up>);
1705 static_assert(is_same_v<typename _Up::error_type, _Er>);
1710 return _Up(unexpect, _M_unex);
1713 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er&>
1715 and_then(_Fn&& __f)
const &
1717 using _Up = __expected::__result0<_Fn>;
1718 static_assert(__expected::__is_expected<_Up>);
1719 static_assert(is_same_v<typename _Up::error_type, _Er>);
1724 return _Up(unexpect, _M_unex);
1727 template<
typename _Fn>
requires is_constructible_v<_Er, _Er>
1729 and_then(_Fn&& __f) &&
1731 using _Up = __expected::__result0<_Fn>;
1732 static_assert(__expected::__is_expected<_Up>);
1733 static_assert(is_same_v<typename _Up::error_type, _Er>);
1738 return _Up(unexpect,
std::move(_M_unex));
1741 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er>
1743 and_then(_Fn&& __f)
const &&
1745 using _Up = __expected::__result0<_Fn>;
1746 static_assert(__expected::__is_expected<_Up>);
1747 static_assert(is_same_v<typename _Up::error_type, _Er>);
1752 return _Up(unexpect,
std::move(_M_unex));
1755 template<
typename _Fn>
1757 or_else(_Fn&& __f) &
1759 using _Gr = __expected::__result<_Fn, _Er&>;
1760 static_assert(__expected::__is_expected<_Gr>);
1761 static_assert(is_same_v<typename _Gr::value_type, _Tp>);
1769 template<
typename _Fn>
1771 or_else(_Fn&& __f)
const &
1773 using _Gr = __expected::__result<_Fn, const _Er&>;
1774 static_assert(__expected::__is_expected<_Gr>);
1775 static_assert(is_same_v<typename _Gr::value_type, _Tp>);
1783 template<
typename _Fn>
1785 or_else(_Fn&& __f) &&
1787 using _Gr = __expected::__result<_Fn, _Er&&>;
1788 static_assert(__expected::__is_expected<_Gr>);
1789 static_assert(is_same_v<typename _Gr::value_type, _Tp>);
1797 template<
typename _Fn>
1799 or_else(_Fn&& __f)
const &&
1801 using _Gr = __expected::__result<_Fn, const _Er&&>;
1802 static_assert(__expected::__is_expected<_Gr>);
1803 static_assert(is_same_v<typename _Gr::value_type, _Tp>);
1811 template<
typename _Fn>
requires is_constructible_v<_Er, _Er&>
1813 transform(_Fn&& __f) &
1815 using _Up = __expected::__result0_xform<_Fn>;
1816 using _Res = expected<_Up, _Er>;
1821 return _Res(unexpect, _M_unex);
1824 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er&>
1826 transform(_Fn&& __f)
const &
1828 using _Up = __expected::__result0_xform<_Fn>;
1829 using _Res = expected<_Up, _Er>;
1834 return _Res(unexpect, _M_unex);
1837 template<
typename _Fn>
requires is_constructible_v<_Er, _Er>
1839 transform(_Fn&& __f) &&
1841 using _Up = __expected::__result0_xform<_Fn>;
1842 using _Res = expected<_Up, _Er>;
1847 return _Res(unexpect,
std::move(_M_unex));
1850 template<
typename _Fn>
requires is_constructible_v<_Er, const _Er>
1852 transform(_Fn&& __f)
const &&
1854 using _Up = __expected::__result0_xform<_Fn>;
1855 using _Res = expected<_Up, _Er>;
1860 return _Res(unexpect,
std::move(_M_unex));
1863 template<
typename _Fn>
1865 transform_error(_Fn&& __f) &
1867 using _Gr = __expected::__result_xform<_Fn, _Er&>;
1868 using _Res = expected<_Tp, _Gr>;
1873 return _Res(__unexpect_inv{}, [&]() {
1879 template<
typename _Fn>
1881 transform_error(_Fn&& __f)
const &
1883 using _Gr = __expected::__result_xform<_Fn, const _Er&>;
1884 using _Res = expected<_Tp, _Gr>;
1889 return _Res(__unexpect_inv{}, [&]() {
1895 template<
typename _Fn>
1897 transform_error(_Fn&& __f) &&
1899 using _Gr = __expected::__result_xform<_Fn, _Er&&>;
1900 using _Res = expected<_Tp, _Gr>;
1905 return _Res(__unexpect_inv{}, [&]() {
1911 template<
typename _Fn>
1913 transform_error(_Fn&& __f)
const &&
1915 using _Gr = __expected::__result_xform<_Fn, const _Er&&>;
1916 using _Res = expected<_Tp, _Gr>;
1921 return _Res(__unexpect_inv{}, [&]() {
1929 template<
typename _Up,
typename _Er2>
1930 requires is_void_v<_Up>
1931 &&
requires (
const _Er& __e,
const _Er2& __e2) {
1932 { __e == __e2 } -> convertible_to<bool>;
1935 friend constexpr bool
1936 operator==(
const expected& __x,
const expected<_Up, _Er2>& __y)
1937 noexcept(
noexcept(bool(__x.error() == __y.error())))
1939 if (__x.has_value() != __y.has_value())
1941 if (__x.has_value())
1943 return __x.error() == __y.error();
1946 template<
typename _Er2>
1947 requires requires (
const _Er& __e,
const _Er2& __e2) {
1948 { __e == __e2 } -> convertible_to<bool>;
1951 friend constexpr bool
1952 operator==(
const expected& __x,
const unexpected<_Er2>& __e)
1953 noexcept(
noexcept(bool(__x.error() == __e.error())))
1955 if (!__x.has_value())
1956 return __x.error() == __e.error();
1960 friend constexpr void
1961 swap(expected& __x, expected& __y)
1962 noexcept(
noexcept(__x.swap(__y)))
1963 requires requires { __x.swap(__y); }
1967 template<
typename,
typename>
friend class expected;
1969 template<
typename _Vp>
1971 _M_assign_unex(_Vp&& __v)
1975 std::construct_at(__builtin_addressof(_M_unex),
1977 _M_has_value =
false;
1983 using __in_place_inv = __expected::__in_place_inv;
1984 using __unexpect_inv = __expected::__unexpect_inv;
1986 template<
typename _Fn>
1988 expected(__in_place_inv, _Fn&& __fn)
1989 : _M_void(), _M_has_value(true)
1992 template<
typename _Fn>
1994 expected(__unexpect_inv, _Fn&& __fn)
1995 : _M_unex(std::
forward<_Fn>(__fn)()), _M_has_value(false)
2007_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.