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

A C++23-like expected.

Constructors, destructors, conversion operators

template <typename... Args, typename = std::enable_if_t<std::is_constructible_v<T, Args...>>>
expected(std::in_place_t, Args && ... args) explicit constexpr noexcept(…)
Construct an expected value directly in-place.
template <typename... Args, typename = std::enable_if_t<std::is_constructible_v<E, Args...>>>
expected(unexpect_t, Args && ... args) explicit constexpr noexcept(…)
Construct an unexpected value directly in-place.

Public functions

template <typename... Args, std::enable_if_t<std::is_constructible_v<T, Args...>>* = nullptr>
auto emplace(Args && ... args) →  decltype(auto) noexcept(…)
auto error() & →  error_type& constexpr noexcept
Get the unexpected value, if one is contained in *this.
template <typename U = value_type, typename = std::enable_if_t<std::is_convertible_v<U, value_type>>>
auto expected(U&& val) →  SCN_IMPLICIT constexpr noexcept(…)
template <typename U = T, std::enable_if_t<!std::is_void_v<U>>* = nullptr>
auto operator*() & →  U& constexpr noexcept
Get the expected value, if one is contained in *this.
template <typename U = T, std::enable_if_t<!std::is_void_v<U>>* = nullptr>
auto value() & →  U& constexpr noexcept
Get the expected value, if one is contained in *this.
template <typename U, typename = std::enable_if_t<std::is_copy_constructible_v<T>&& std::is_convertible_v<U, T>>>
auto value_or(U&& default_value) const & →  T constexpr noexcept(…)

Function documentation

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

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

template <typename T, typename E>
template <typename U = value_type, typename = std::enable_if_t<std::is_convertible_v<U, value_type>>>
SCN_IMPLICIT scn::v3::expected::expected(U&& val) constexpr noexcept(…)

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

template <typename T, typename E>
template <typename U, typename = std::enable_if_t<std::is_copy_constructible_v<T>&& std::is_convertible_v<U, T>>>
T scn::v3::expected::value_or(U&& default_value) const & constexpr noexcept(…)

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