std::expected::value_or(3)
πΈ NAME πΈ
std::expected::value_or β okay bestie, the name is literally std::expected::value_or, and this is the C++ Standard Libary manual page for std::expected::value_or(3) (yes, βLibaryβ is spelled like that in the source, no cap). Itβs giving βfallback value when your expected doesnβt have the goodsβ energy. π«Ά
β¨ Synopsis β¨
template< class U > (1) (since C++23)
constexpr T value_or( U&& default_value ) const&;
template< class U > (2) (since C++23)
constexpr T value_or( U&& default_value ) &&;
Returns the contained value if *this contains an expected value, otherwise returns default_value. Slay. π
- Returns
bool(*this) ? **this : static_cast<T>(std::forward<U>(default_value)) - Returns
bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(default_value))
π Parameters π
default_valueβ the value to use in case*thisdoes not contain an expected value. Thatβs your fallback bestie, the one who shows up when the value doesnβt. π
π§ Type requirements π§
Tmust meet the requirements ofCopyConstructiblein order to use overload (1).Tmust meet the requirements ofMoveConstructiblein order to use overload (2).U&&must be convertible toT.
π Return value π
The currently contained value if *this contains an expected value, or default_value otherwise. Thatβs it, thatβs the tea. β
π₯ Exceptions π₯
Any exception thrown by the selected constructor of the return value T. So yeah, if Tβs constructor decides to throw, that energy comes straight through. π
π Notes π
If T is (possibly cv-qualified) void, this member is not declared. Periodt. π«Ά
π Example π
This section is incomplete.
Reason: no example.
π See also π
valueβ returns the expected value (public member function). lowkey the main character version of this. β¨
π·οΈ Category π·οΈ
- Todo no example
made with π by http://cppreference.com β 2024.06.10 π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms