template <typename T, typename E>
scn::expected class

A C++23-like expected.

Constructors, destructors, conversion operators

template <typename U = value_type, typename = std::enable_if_t<std::is_convertible<U, value_type>::value>>
expected(U&& val) constexpr
template <typename... Args, typename = std::enable_if_t<std::is_constructible<T, Args...>::value>>
expected(std::in_place_t, Args && ... args) explicit constexpr
Construct an expected value directly in-place.
template <typename... Args, typename = std::enable_if_t<std::is_constructible<E, Args...>::value>>
expected(unexpect_t, Args && ... args) explicit constexpr
Construct an unexpected value directly in-place.

Public functions

template <typename... Args, typename std::enable_if_t<std::is_constructible<T, Args...>::value>* = nullptr>
auto emplace(Args && ... args) →  decltype(auto)
auto error() & →  error_type& constexpr
Get the unexpected value, if one is contained in *this.
template <typename U = T, std::enable_if_t<!std::is_void<U>::value>* = nullptr>
auto operator*() & →  U& constexpr
Get the expected value, if one is contained in *this.
template <typename U = T, std::enable_if_t<!std::is_void<U>::value>* = nullptr>
auto value() & →  U& constexpr
Get the expected value, if one is contained in *this.
template <typename U, typename = std::enable_if_t<std::is_copy_constructible<T>::value&& std::is_convertible<U, T>::value>>
auto value_or(U&& default_value) const & →  T constexpr

Function documentation

template <typename T, typename E>
template <typename U = value_type, typename = std::enable_if_t<std::is_convertible<U, value_type>::value>>
scn::expected::expected(U&& val) constexpr

Construct an expected value. Intentionally non-explicit, to make constructing an expected value as transparent as possible.

template <typename T, typename E>
template <typename... Args, typename std::enable_if_t<std::is_constructible<T, Args...>::value>* = nullptr>
decltype(auto) scn::expected::emplace(Args && ... args)

Destroys the contained value, and then initializes the expected value directly in-place.

template <typename T, typename E>
template <typename U, typename = std::enable_if_t<std::is_copy_constructible<T>::value&& std::is_convertible<U, T>::value>>
T scn::expected::value_or(U&& default_value) const & constexpr

Returns the expected value if *this contains one, otherwise returns default_value