userver: utils::expected< S, E > Class Template Reference
Loading...
Searching...
No Matches
utils::expected< S, E > Class Template Reference

#include <userver/utils/expected.hpp>

Detailed Description

template<class S, class E>
class utils::expected< S, E >

For holding a value or an error.

Definition at line 85 of file expected.hpp.

Public Member Functions

 expected (const S &success)
 expected (S &&success)
 expected (const unexpected< E > &error)
 expected (unexpected< E > &&error)
template<class G>
requires std::is_convertible_v<G, E>
 expected (const unexpected< G > &error)
template<class G>
requires std::is_convertible_v<G, E>
 expected (unexpected< G > &&error)
bool has_value () const noexcept
 Check whether *this contains an expected value.
 operator bool () const noexcept
 Check whether *this contains an expected value.
S & value () &
 Return reference to the value or throws bad_expected_access if it's not available.
S && value () &&
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
const S & value () const &
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
S & operator* () &noexcept
 Unchecked access to the contained value.
S && operator* () &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
const S & operator* () const &noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
S * operator-> () noexcept
 Unchecked access to the members of the contained value.
const S * operator-> () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
E & error ()
 Return reference to the error value or throws bad_expected_access if it's not available.
const E & error () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Constructor & Destructor Documentation

◆ expected() [1/7]

template<class S, class E>
utils::expected< S, E >::expected ( )
constexpr

Definition at line 206 of file expected.hpp.

◆ expected() [2/7]

template<class S, class E>
utils::expected< S, E >::expected ( const S & success)

Definition at line 211 of file expected.hpp.

◆ expected() [3/7]

template<class S, class E>
utils::expected< S, E >::expected ( S && success)

Definition at line 216 of file expected.hpp.

◆ expected() [4/7]

template<class S, class E>
utils::expected< S, E >::expected ( const unexpected< E > & error)

Definition at line 221 of file expected.hpp.

◆ expected() [5/7]

template<class S, class E>
utils::expected< S, E >::expected ( unexpected< E > && error)

Definition at line 226 of file expected.hpp.

◆ expected() [6/7]

template<class S, class E>
requires std::is_convertible_v<G, E>
template<class G>
requires std::is_convertible_v<G, E>
utils::expected< S, E >::expected ( const unexpected< G > & error)

Definition at line 233 of file expected.hpp.

◆ expected() [7/7]

template<class S, class E>
requires std::is_convertible_v<G, E>
template<class G>
requires std::is_convertible_v<G, E>
utils::expected< S, E >::expected ( unexpected< G > && error)

Definition at line 240 of file expected.hpp.

Member Function Documentation

◆ error() [1/2]

template<class S, class E>
E & utils::expected< S, E >::error ( )

Return reference to the error value or throws bad_expected_access if it's not available.

Exceptions
utils::bad_expected_accessif success value is not available

Definition at line 307 of file expected.hpp.

◆ error() [2/2]

template<class S, class E>
const E & utils::expected< S, E >::error ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 316 of file expected.hpp.

◆ has_value()

template<class S, class E>
bool utils::expected< S, E >::has_value ( ) const
noexcept

Check whether *this contains an expected value.

Definition at line 245 of file expected.hpp.

◆ operator bool()

template<class S, class E>
utils::expected< S, E >::operator bool ( ) const
explicitnoexcept

Check whether *this contains an expected value.

Definition at line 250 of file expected.hpp.

◆ operator*() [1/3]

template<class S, class E>
S && utils::expected< S, E >::operator* ( ) &&
noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 284 of file expected.hpp.

◆ operator*() [2/3]

template<class S, class E>
S & utils::expected< S, E >::operator* ( ) &
noexcept

Unchecked access to the contained value.

Warning
The behavior is undefined if *this does not contain a value; use value for checked access.

Definition at line 278 of file expected.hpp.

◆ operator*() [3/3]

template<class S, class E>
const S & utils::expected< S, E >::operator* ( ) const &
noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 289 of file expected.hpp.

◆ operator->() [1/2]

template<class S, class E>
const S * utils::expected< S, E >::operator-> ( ) const
noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 301 of file expected.hpp.

◆ operator->() [2/2]

template<class S, class E>
S * utils::expected< S, E >::operator-> ( )
noexcept

Unchecked access to the members of the contained value.

Warning
The behavior is undefined if *this does not contain a value; use value for checked access.

Definition at line 295 of file expected.hpp.

◆ value() [1/3]

template<class S, class E>
S & utils::expected< S, E >::value ( ) &

Return reference to the value or throws bad_expected_access if it's not available.

Exceptions
utils::bad_expected_accessif *this contain an unexpected value

Definition at line 255 of file expected.hpp.

◆ value() [2/3]

template<class S, class E>
S && utils::expected< S, E >::value ( ) &&

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 264 of file expected.hpp.

◆ value() [3/3]

template<class S, class E>
const S & utils::expected< S, E >::value ( ) const &

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 269 of file expected.hpp.


The documentation for this class was generated from the following file: