GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
* Sign Up! *

Support
Customer Portal
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::expected::or_else(3) C++ Standard Libary std::expected::or_else(3)

std::expected::or_else - std::expected::or_else


template< class F > (1) (since C++23)
constexpr auto or_else( F&& f ) &;
template< class F > (2) (since C++23)
constexpr auto or_else( F&& f ) const&;
template< class F > (3) (since C++23)
constexpr auto or_else( F&& f ) &&;
template< class F > (4) (since C++23)
constexpr auto or_else( F&& f ) const&&;


If *this contains an unexpected value, invokes f with the argument error() and
returns its result; otherwise, returns a std::expected object that contains a copy
of the contained expected value (obtained from operator*).


1,2) Given type G as std::remove_cvref_t<std::invoke_result_t<F,
decltype(error())>>.
If G is not a specialization of std::expected, or std::is_same_v<G::value_type, T>
is false, the program is ill-formed.
The effect is equivalent to


if (has_value())
{
if constexpr (std::is_void_v<T>)
return G();
else
return G(std::in_place, **this);
}
else
return std::invoke(std::forward<F>(f), error());


These overloads participate in overload resolution only if std::is_void_v<T> or
std::is_constructible_v<T, decltype(**this)> is true.
3,4) Given type G as std::remove_cvref_t<std::invoke_result_t<F,
decltype(std::move(error()))>>.
If G is not a specialization of std::expected, or std::is_same_v<G::value_type, T>
is false, the program is ill-formed.
The effect is equivalent to


if (has_value())
{
if constexpr (std::is_void_v<T>)
return G();
else
return G(std::in_place, std::move(**this));
}
else
return std::invoke(std::forward<F>(f), std::move(error()));


These overloads participate in overload resolution only if std::is_void_v<T> or
std::is_constructible_v<T, decltype(std::move(**this))> is true.


f - a suitable function or Callable object that returns a std::expected


The result of f, or a std::expected object that contains a copy of the expected
value, as described above.


Feature-test macro Value Std Feature
__cpp_lib_expected 202211L (C++23) Monadic functions for std::expected


This section is incomplete
Reason: no example


Defect reports


The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.


DR Applied to Behavior as published Correct behavior
LWG 3938 C++23 or_else was ill-formed if T is not (possibly made well-formed
cv-qualified) void and E is not copyable


returns the expected itself if it contains an expected value;
transform_error otherwise, returns an expected containing the transformed unexpected
value
(public member function)


* Todo no example

2024.06.10 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.