Template Class Expected#
Defined in File Expected.h
Class Documentation#
-
template<typename T, typename E>
class Expected# The class template TRAP:Expected provides a way to store either of two values. An object of TRAP::Expected at any given time either holds an expected value of type T, or an unexpected value of type E. TRAP::Expected is never valueless.
The stored value is allocated directly within the storage occupied by the expected object. No dynamic memory allocation takes place.
A program is ill-formed if it instantiates an expected with a reference type, a function type, or a specialization of TRAP::Unexpected. In addition, T must not be std::in_place_t or TRAP::Unexpect_t.
- Template Parameters:
T – The type of the expected value. The type must either be (possibly cv-qualified) void, or meet the Destructible requirements (in particular, array and reference types are not allowed).
E – The type of the unexpected value. The type must meet the Destructible requirements, and must be a valid template argument for TRAP::Unexpected (in particular, arrays, non-object types, and cv-qualified types are not allowed).
Public Types
-
using unexpected_type = TRAP::Unexpected<E>#
-
template<typename U>
using rebind = TRAP::Expected<U, error_type>#
Public Functions
-
inline constexpr Expected() noexcept(std::is_nothrow_default_constructible_v<T>)#
Constructs a new expected object. Default constructor. If T is not (possibly cv-qualified) void, constructs an object that contains an expected value, which is value-initialized.
After construction, HasValue() returns true.
-
constexpr Expected(const Expected &other) = default#
Constructs a new expected object. Copy constructor. If other.HasValue() is false, the new object contains an unexpected value, which is direct-initialized from other.Error(). Otherwise, if T is not (possibly cv-qualified) void, the new object contains an expected value, which is direct-initialized from *other.
After construction, HasValue() is equal to other.HasValue().
- Parameters:
other – Another expected object whose contained value is copied.
-
inline constexpr Expected(const Expected &other) noexcept(std::conjunction_v<std::is_nothrow_copy_constructible<T>, std::is_nothrow_copy_constructible<E>>)
Constructs a new expected object. Copy constructor. If other.HasValue() is false, the new object contains an unexpected value, which is direct-initialized from other.Error(). Otherwise, if T is not (possibly cv-qualified) void, the new object contains an expected value, which is direct-initialized from *other.
After construction, HasValue() is equal to other.HasValue().
- Parameters:
other – Another expected object whose contained value is copied.
-
constexpr Expected(Expected &&other) = default#
Constructs a new expected object. Move constructor. If other.HasValue() is false, the new object contains an unexpected value, which is direct-initialized from std::move(other.Error()). Otherwise, if T is not (possibly cv-qualified) void, the new object contains an expected value, which is direct-initialized from std::move(*other).
After construction, HasValue() is equal to other.HasValue().
- Parameters:
other – Another expected object whose contained value is copied.
-
inline constexpr Expected(Expected &&other) noexcept(std::conjunction_v<std::is_nothrow_move_constructible<T>, std::is_nothrow_move_constructible<E>>)
Constructs a new expected object. Move constructor. If other.HasValue() is false, the new object contains an unexpected value, which is direct-initialized from std::move(other.Error()). Otherwise, if T is not (possibly cv-qualified) void, the new object contains an expected value, which is direct-initialized from std::move(*other).
After construction, HasValue() is equal to other.HasValue().
- Parameters:
other – Another expected object whose contained value is copied.
- template<typename U, typename G> constexpr explicit (ExplicitConvertible< const U &, const G & >) Expected(const Expected< U
Constructs a new expected object. Let.
UF be std::add_lvalue_reference_t<const U>, and
GF be const G&.
If other.HasValue() is false, the new object contains an unexpected value, which is direct-initialized from std::forward<GF>(other.Error()). Otherwise, if T is not (possibly cv-qualified) void, the new object contains an expected value, which is direct-initialized from std::forward<UF>(*other). After construction, HasValue() is equal to other.HasValue().
- Parameters:
other – Another expected object whose contained value is copied.
- inline constexpr G &other noexcept (std::conjunction_v< std::is_nothrow_constructible< T, const U >, std::is_nothrow_constructible< E, const G & > >)
- template<typename U, typename G> constexpr explicit (ExplicitConvertible< U, G >) Expected(Expected< U
Constructs a new expected object. Let.
UF be U, and
GF be G.
If other.HasValue() is false, the new object contains an unexpected value, which is direct-initialized from std::forward<GF>(other.Error()). Otherwise, if T is not (possibly cv-qualified) void, the new object contains an expected value, which is direct-initialized from std::forward<UF>(*other). After construction, HasValue() is equal to other.HasValue().
- Parameters:
other – Another expected object whose contained value is copied.
- inline constexpr G &&other noexcept (std::conjunction_v< std::is_nothrow_constructible< T, U >, std::is_nothrow_constructible< E, G > >)
-
template<typename U = T>
inline explicit(!std::is_convertible_v<U, T>) constexpr Expected(U &&v) noexcept(std::is_nothrow_constructible_v<T, U>)# Constructs a new expected object. Constructs an object that contains an expected value, initialized as if direct-initializing (but not direct-list-initializing) an object of type T with the expression std::forward<U>(v).
After construction, HasValue() returns true.
- Parameters:
v – Value with which to initialize the contained value.
-
template<typename G = E>
inline explicit(!std::is_convertible_v<const G&, E>) constexpr Expected(const Unexpected<G> &u) noexcept(std::is_nothrow_constructible_v<E, const G&>)# Constructs a new expected object. Let GF be const G&.
Constructs an object that contains an unexpected value, which is direct-initialized from std::forward<GF>(e.Error()). After construction, HasValue() returns false.
- Parameters:
u – TRAP::Unexpected object whose contained value is copied.
-
template<typename G = E>
inline explicit(!std::is_convertible_v<G, E>) constexpr Expected(Unexpected<G> &&u) noexcept(std::is_nothrow_constructible_v<E, G>)# Constructs a new expected object. Let GF be G.
Constructs an object that contains an unexpected value, which is direct-initialized from std::forward<GF>(e.Error()). After construction, HasValue() returns false.
- Parameters:
u – TRAP::Unexpected object whose contained value is copied.
-
template<typename ...Args>
inline explicit constexpr Expected(std::in_place_t _, Args&&... args) noexcept(std::is_nothrow_constructible_v<T, Args...>)# Constructs a new expected object. Constructs an object that contains an expected value, which is direct-initialized from the arguments std::forward<Args>(args)….
After construction, HasValue() return true.
- Parameters:
args – Arguments with which to initialize the contained value.
-
template<typename U, typename ...Args>
inline explicit constexpr Expected(std::in_place_t _, std::initializer_list<U> il, Args&&... args) noexcept(std::is_nothrow_constructible_v<T, std::initializer_list<U>&, Args...>)# Constructs a new expected object. Constructs an object that contains an expected value, which is direct-initialized from the arguments il, std::forward<Args>(args)….
After construction, HasValue() return true.
- Parameters:
il – Initializer list with which to initialize the contained value.
args – Arguments with which to initialize the contained value.
-
template<typename ...Args>
inline explicit constexpr Expected(Unexpect_t _, Args&&... args) noexcept(std::is_nothrow_constructible_v<E, Args...>)# Constructs a new expected object. Constructs an object that contains an unexpected value, which is direct-initialized from the arguments std::forward<Args>(args)….
After construction, HasValue() returns false.
- Parameters:
args – Arguments with which to initialize the contained value.
-
template<typename U, typename ...Args>
inline explicit constexpr Expected(Unexpect_t _, std::initializer_list<U> il, Args&&... args) noexcept(std::is_nothrow_constructible_v<E, std::initializer_list<U>&, Args...>)# Constructs a new expected object. Constructs an object that contains an unexpected value, which is direct-initialized from the arguments il, std::forward<Args>(args)….
After construction, HasValue() returns false.
- Parameters:
il – Initializer list with which to initialize the contained value.
args – Arguments with which to initialize the contained value.
-
constexpr ~Expected() = default#
Destroys the currently contained value. Thas if, if HasValue() is false, destroys the unexpected value; otherwise, if T is not (possibly cv-qualified) void, destroys the expected value.
-
inline constexpr ~Expected()
Destroys the currently contained value. Thas if, if HasValue() is false, destroys the unexpected value; otherwise, if T is not (possibly cv-qualified) void, destroys the expected value.
-
constexpr Expected &operator=(const Expected &other) = delete#
Assigns a new value to an existing expected object. Assigns the state of other.
If this->HasValue() equals other.HasValue(), assigns the value contained in other. Does nothing if T is (possibly cv-qualified) void and other.HasValue() is true.
Otherwise, destroys the currently contained value (does nothing if this->HasValue() is true and T is (possibly cv-qualified) void), and makes *this contain a copy of the value contained in other.
If other.HasValue() is true and T is (possibly cv-qualified) void, does not construct the new value. Otherwise, the new value is copy-constructed from *other. If an exception is thrown, the old value is retained; *this does not become valueless.
If no exception was thrown, after assignment, HasValue() is equal to other.HasValue().
- Parameters:
other – Another expected object whose contained value to assign.
- Returns:
*this.
-
inline constexpr Expected &operator=(const Expected &other) noexcept(std::conjunction_v<std::is_nothrow_copy_constructible<T>, std::is_nothrow_copy_constructible<E>, std::is_nothrow_copy_assignable<T>, std::is_nothrow_copy_assignable<E>>)
Assigns a new value to an existing expected object. Assigns the state of other.
If this->HasValue() equals other.HasValue(), assigns the value contained in other. Does nothing if T is (possibly cv-qualified) void and other.HasValue() is true.
Otherwise, destroys the currently contained value (does nothing if this->HasValue() is true and T is (possibly cv-qualified) void), and makes *this contain a copy of the value contained in other.
If other.HasValue() is true and T is (possibly cv-qualified) void, does not construct the new value. Otherwise, the new value is copy-constructed from *other. If an exception is thrown, the old value is retained; *this does not become valueless.
If no exception was thrown, after assignment, HasValue() is equal to other.HasValue().
- Parameters:
other – Another expected object whose contained value to assign.
- Returns:
*this.
-
inline constexpr Expected &operator=(Expected &&other) noexcept(std::conjunction_v<std::is_nothrow_move_constructible<T>, std::is_nothrow_move_constructible<E>, std::is_nothrow_move_assignable<T>, std::is_nothrow_move_assignable<E>>)#
Assigns a new value to an existing expected object. Assigns the state of other.
If this->HasValue() equals other.HasValue(), assigns the value contained in other. Does nothing if T is (possibly cv-qualified) void and other.HasValue() is true.
Otherwise, destroys the currently contained value (does nothing if this->HasValue() is true and T is (possibly cv-qualified) void), and makes *this contain a copy of the value contained in other.
If other.HasValue() is true and T is (possibly cv-qualified) void, does not construct the new value. Otherwise, the new value is move-constructed from other.Error(), as appropriate. If an exception is thrown, the old value is retained; *this does not become valueless.
If no exception was thrown, after assignment, HasValue() is equal to other.HasValue().
- Parameters:
other – Another expected object whose contained value to assign.
- Returns:
*this.
-
template<typename U = T>
inline constexpr Expected &operator=(U &&v)# Assigns a new value to an existing expected object. Assigns from expected value,.
If this->HasValue() is true, equivalent to **this = std::forward<U>(v).
Otherwise, destroys the value contained in *this, and makes *this contain a value initialized from std::forward<U>(v). If an exception is thrown, the old value is retained; *this does not become valueless.
If no exception was thrown, after assignment, this->HasValue() is true.
- Parameters:
v – Value to assign to the contained value.
-
template<typename G>
inline constexpr Expected &operator=(const Unexpected<G> &e)# Assigns a new value to an existing expected object. Assigns from unexpected value. Let GF be const G&.
If this->HasValue() is true, destroys the value contained in *this (does nothing if T is (possibly cv-qualified) void), and makes *this contain a value initialized from std::forward<GF>(e.Error()). If an exception is thrown, the old value is retained; *this does not become valueless.
Otherwise, equivalent to this->Error() = std::forward<GF>(e.Error()).
If no exception was thrown, after assignment, this->HasValue() is false.
- Parameters:
e – TRAP::Unexpected object whose contained value to assign.
-
template<typename G>
inline constexpr Expected &operator=(Unexpected<G> &&e)# Assigns a new value to an existing expected object. Assigns from unexpected value. Let GF be G.
If this->HasValue() is true, destroys the value contained in *this (does nothing if T is (possibly cv-qualified) void), and makes *this contain a value initialized from std::forward<GF>(e.Error()). If an exception is thrown, the old value is retained; *this does not become valueless.
Otherwise, equivalent to this->Error() = std::forward<GF>(e.Error()).
If no exception was thrown, after assignment, this->HasValue() is false.
- Parameters:
e – TRAP::Unexpected object whose contained value to assign.
-
template<typename ...Args>
inline constexpr T &Emplace(Args&&... args) noexcept# Constructs an expected value in-place. After the call, HasValue() returns true. Destroys the contained value, then initializes the expected value contained in *this as if by direct-initializing an object of type T from the arguments std::forward<Args>(args)….
- Parameters:
args – The arguments to pass to the constructor.
- Returns:
A reference to the new contained value.
-
template<typename U, typename ...Args>
inline constexpr T &Emplace(std::initializer_list<U> il, Args&&... args) noexcept# Constructs an expected value in-place. After the call, HasValue() returns true. Destroys the contained value, then initializes the expected value contained in *this as if by direct-initializing an object of type T from the arguments il, std::forward<Args>(args)….
- Parameters:
il – The initializer list to pass to the constructor.
args – The arguments to pass to the constructor.
- Returns:
A reference to the new contained value.
-
inline constexpr void Swap(Expected &x) noexcept(std::conjunction_v<std::is_nothrow_move_constructible<T>, std::is_nothrow_move_constructible<E>, std::is_nothrow_swappable<T&>, std::is_nothrow_swappable<E&>>)#
Swaps the contents with those of other.
- Parameters:
x – The expected object to exchange the contents with.
-
inline constexpr const T *operator->() const noexcept#
Accesses the expected value contained in *this. Returns a pointer to the contained value.
The behaviour is undefined if this->HasValue() is false.
Note
This operator does not check whether the optional contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value(), ValueOr() or ValueOrElse() may be used.
- Returns:
Pointer to the contained value.
-
inline constexpr T *operator->() noexcept#
Accesses the expected value contained in *this. Returns a pointer to the contained value.
The behaviour is undefined if this->HasValue() is false.
Note
This operator does not check whether the optional contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value(), ValueOr() or ValueOrElse() may be used.
- Returns:
Pointer to the contained value.
-
inline constexpr const T &operator*() const & noexcept#
Accesses the expected value contained in *this. Returns a reference to the contained value.
The behaviour is undefined if this->HasValue() is false.
Note
This operator does not check whether the optional contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value(), ValueOr() or ValueOrElse() may be used.
- Returns:
Reference to the contained value.
-
inline constexpr T &operator*() & noexcept#
Accesses the expected value contained in *this. Returns a reference to the contained value.
The behaviour is undefined if this->HasValue() is false.
Note
This operator does not check whether the optional contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value(), ValueOr() or ValueOrElse() may be used.
- Returns:
Reference to the contained value.
-
inline constexpr const T &&operator*() const && noexcept#
Accesses the expected value contained in *this. Returns a reference to the contained value.
The behaviour is undefined if this->HasValue() is false.
Note
This operator does not check whether the optional contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value(), ValueOr() or ValueOrElse() may be used.
- Returns:
Reference to the contained value.
-
inline constexpr T &&operator*() && noexcept#
Accesses the expected value contained in *this. Returns a reference to the contained value.
The behaviour is undefined if this->HasValue() is false.
Note
This operator does not check whether the optional contains a value! You can do so manually by using HasValue() or simply operator bool(). Alternatively, if checked access is needed, Value(), ValueOr() or ValueOrElse() may be used.
- Returns:
Reference to the contained value.
-
inline explicit constexpr operator bool() const noexcept#
Checks whether *this contains an expected value.
Note
A TRAP::Expected object is never empty. If HasValue() returns true, operator* can be used to access the contained value; otherwise, Error() can be used.
- Returns:
true if *this contains an expected value, false if *this contains an unexpected value.
-
inline constexpr bool HasValue() const noexcept#
Checks whether *this contains an expected value.
Note
A TRAP::Expected object is never empty. If HasValue() returns true, operator* can be used to access the contained value; otherwise, Error() can be used.
- Returns:
true if *this contains an expected value, false if *this contains an unexpected value.
-
inline constexpr const T &Value() const &#
If *this contains an expected value, returns a reference to the contained value. Returns nothing if T is (possibly cv-qualified) void. Otherwise, throws an exception of type TRAP::BadExpectedAccess<std::decay_t<E>> that contains a copy of Error().
- Returns:
The expected value contained in *this.
-
inline constexpr T &Value() &#
If *this contains an expected value, returns a reference to the contained value. Returns nothing if T is (possibly cv-qualified) void. Otherwise, throws an exception of type TRAP::BadExpectedAccess<std::decay_t<E>> that contains a copy of Error().
- Returns:
The expected value contained in *this.
-
inline constexpr const T &&Value() const &&#
If *this contains an expected value, returns a reference to the contained value. Returns nothing if T is (possibly cv-qualified) void. Otherwise, throws an exception of type TRAP::BadExpectedAccess<std::decay_t<E>> that contains a copy of Error().
- Returns:
The expected value contained in *this.
-
inline constexpr T &&Value() &&#
If *this contains an expected value, returns a reference to the contained value. Returns nothing if T is (possibly cv-qualified) void. Otherwise, throws an exception of type TRAP::BadExpectedAccess<std::decay_t<E>> that contains a copy of Error().
- Returns:
The expected value contained in *this.
-
inline constexpr const E &Error() const & noexcept#
Accesses the unexpected value contained in *this. The behaviour is undefined if this->HasValue() is true.
- Returns:
Reference to the unexpected value contained in *this.
-
inline constexpr E &Error() & noexcept#
Accesses the unexpected value contained in *this. The behaviour is undefined if this->HasValue() is true.
- Returns:
Reference to the unexpected value contained in *this.
-
inline constexpr const E &&Error() const && noexcept#
Accesses the unexpected value contained in *this. The behaviour is undefined if this->HasValue() is true.
- Returns:
Reference to the unexpected value contained in *this.
-
inline constexpr E &&Error() && noexcept#
Accesses the unexpected value contained in *this. The behaviour is undefined if this->HasValue() is true.
- Returns:
Reference to the unexpected value contained in *this.
-
template<typename U>
inline constexpr T ValueOr(U &&v) const & noexcept(std::conjunction_v<std::is_nothrow_copy_constructible<T>, std::is_nothrow_convertible<U, T>>)# Returns the contained value if *this contains an expected value, otherwise returns v.
- Parameters:
v – The value to use in case *this does not contain an expected value.
- Returns:
The currently contained value if *this contains an expected value, or v otherwise.
-
template<typename U>
inline constexpr T ValueOr(U &&v) && noexcept(std::conjunction_v<std::is_nothrow_move_constructible<T>, std::is_nothrow_convertible<U, T>>)# Returns the contained value if *this contains an expected value, otherwise returns v.
- Parameters:
v – The value to use in case *this does not contain an expected value.
- Returns:
The currently contained value if *this contains an expected value, or v otherwise.
-
template<typename F>
inline constexpr T ValueOrElse(F &&f) const &# Returns the contained value if *this contains an expected value, otherwise returns the result of f.
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
The currently contained value if *this contains an expected value, or result of f otherwise.
-
template<typename F>
inline constexpr T ValueOrElse(F &&f) &&# Returns the contained value if *this contains an expected value, otherwise returns the result of f.
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
The currently contained value if *this contains an expected value, or result of f otherwise.
-
template<typename G = E>
inline constexpr E ErrorOr(G &&e) const &# Returns the contained value if *this contains an unexpected value, otherwise returns e.
- Parameters:
e – The value to use in case *this does contain an expected value.
- Returns:
The currently contained value if *this contains an unexpected value, or e otherwise.
-
template<typename G = E>
inline constexpr E ErrorOr(G &&e) &&# Returns the contained value if *this contains an unexpected value, otherwise returns e.
- Parameters:
e – The value to use in case *this does contain an expected value.
- Returns:
The currently contained value if *this contains an unexpected value, or e otherwise.
-
template<typename Fn>
inline constexpr auto AndThen(Fn &&f) &# If *this contains an expected value, invokes f and returns its result; otherwise, returns a TRAP::Expected object that contains a copy of Error().
If T is bot (possibly cv-qualified) void, the contained expected value (obtained from operator*) is passed as an argument to f; otherwise f takes no argument.
- Parameters:
f – A suitable function or Callable object that returns a TRAP::Expected.
- Returns:
The result of f or a TRAP::Expected object that contains an error value, as described above.
-
template<typename Fn>
inline constexpr auto AndThen(Fn &&f) const &# If *this contains an expected value, invokes f and returns its result; otherwise, returns a TRAP::Expected object that contains a copy of Error().
If T is bot (possibly cv-qualified) void, the contained expected value (obtained from operator*) is passed as an argument to f; otherwise f takes no argument.
- Parameters:
f – A suitable function or Callable object that returns a TRAP::Expected.
- Returns:
The result of f or a TRAP::Expected object that contains an error value, as described above.
-
template<typename Fn>
inline constexpr auto AndThen(Fn &&f) &&# If *this contains an expected value, invokes f and returns its result; otherwise, returns a TRAP::Expected object that contains a copy of Error().
If T is bot (possibly cv-qualified) void, the contained expected value (obtained from operator*) is passed as an argument to f; otherwise f takes no argument.
- Parameters:
f – A suitable function or Callable object that returns a TRAP::Expected.
- Returns:
The result of f or a TRAP::Expected object that contains an error value, as described above.
-
template<typename Fn>
inline constexpr auto AndThen(Fn &&f) const &&# If *this contains an expected value, invokes f and returns its result; otherwise, returns a TRAP::Expected object that contains a copy of Error().
If T is bot (possibly cv-qualified) void, the contained expected value (obtained from operator*) is passed as an argument to f; otherwise f takes no argument.
- Parameters:
f – A suitable function or Callable object that returns a TRAP::Expected.
- Returns:
The result of f or a TRAP::Expected object that contains an error value, as described above.
-
template<typename Fn>
inline constexpr auto OrElse(Fn &&f) &# If this contains an uexpected value, invokes f with the argument Error() and returns its result; otherwise, returns a TRAP::Expected object that contains a copy of the contained expected value (obtained from operator).
- Parameters:
f – A suitable function or Callable object that returns a TRAP::Expected.
- Returns:
The result of f, or a TRAP::Exepected object that contains a copy of the expected value, as described above.
-
template<typename Fn>
inline constexpr auto OrElse(Fn &&f) const &# If this contains an uexpected value, invokes f with the argument Error() and returns its result; otherwise, returns a TRAP::Expected object that contains a copy of the contained expected value (obtained from operator).
- Parameters:
f – A suitable function or Callable object that returns a TRAP::Expected.
- Returns:
The result of f, or a TRAP::Exepected object that contains a copy of the expected value, as described above.
-
template<typename Fn>
inline constexpr auto OrElse(Fn &&f) &&# If this contains an uexpected value, invokes f with the argument Error() and returns its result; otherwise, returns a TRAP::Expected object that contains a copy of the contained expected value (obtained from operator).
- Parameters:
f – A suitable function or Callable object that returns a TRAP::Expected.
- Returns:
The result of f, or a TRAP::Exepected object that contains a copy of the expected value, as described above.
-
template<typename Fn>
inline constexpr auto OrElse(Fn &&f) const &&# If this contains an uexpected value, invokes f with the argument Error() and returns its result; otherwise, returns a TRAP::Expected object that contains a copy of the contained expected value (obtained from operator).
- Parameters:
f – A suitable function or Callable object that returns a TRAP::Expected.
- Returns:
The result of f, or a TRAP::Exepected object that contains a copy of the expected value, as described above.
-
template<typename Fn>
inline constexpr auto Transform(Fn &&f) &# If *this contains an expected value, invokes f and returns TRAP::Expected object that contains its result; otherwise, returns a TRAP::Expected object that contains a copy of Error().
If T is not (possibly cv-qualified) void, the contained value (obtained from operator*) is passed as an argument to f; otherwise f takes no argument.
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
A TRAP::Expected object containing either the result of f or an error value, as described above.
-
template<typename Fn>
inline constexpr auto Transform(Fn &&f) const &# If *this contains an expected value, invokes f and returns TRAP::Expected object that contains its result; otherwise, returns a TRAP::Expected object that contains a copy of Error().
If T is not (possibly cv-qualified) void, the contained value (obtained from operator*) is passed as an argument to f; otherwise f takes no argument.
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
A TRAP::Expected object containing either the result of f or an error value, as described above.
-
template<typename Fn>
inline constexpr auto Transform(Fn &&f) &&# If *this contains an expected value, invokes f and returns TRAP::Expected object that contains its result; otherwise, returns a TRAP::Expected object that contains a copy of Error().
If T is not (possibly cv-qualified) void, the contained value (obtained from operator*) is passed as an argument to f; otherwise f takes no argument.
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
A TRAP::Expected object containing either the result of f or an error value, as described above.
-
template<typename Fn>
inline constexpr auto Transform(Fn &&f) const &&# If *this contains an expected value, invokes f and returns TRAP::Expected object that contains its result; otherwise, returns a TRAP::Expected object that contains a copy of Error().
If T is not (possibly cv-qualified) void, the contained value (obtained from operator*) is passed as an argument to f; otherwise f takes no argument.
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
A TRAP::Expected object containing either the result of f or an error value, as described above.
-
template<typename Fn>
inline constexpr auto TransformError(Fn &&f) &# If this contains an error value, invokes f with the argument Error() and returns a TRAP::Expected object that contains its result; otherwise, returns a TRAP::Expected object that contains a copy of the contained expected value (obtained from operator).
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
A TRAP::Expected object containing either the result of f or an expected value, as described above.
-
template<typename Fn>
inline constexpr auto TransformError(Fn &&f) const &# If this contains an error value, invokes f with the argument Error() and returns a TRAP::Expected object that contains its result; otherwise, returns a TRAP::Expected object that contains a copy of the contained expected value (obtained from operator).
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
A TRAP::Expected object containing either the result of f or an expected value, as described above.
-
template<typename Fn>
inline constexpr auto TransformError(Fn &&f) &&# If this contains an error value, invokes f with the argument Error() and returns a TRAP::Expected object that contains its result; otherwise, returns a TRAP::Expected object that contains a copy of the contained expected value (obtained from operator).
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
A TRAP::Expected object containing either the result of f or an expected value, as described above.
-
template<typename Fn>
inline constexpr auto TransformError(Fn &&f) const &&# If this contains an error value, invokes f with the argument Error() and returns a TRAP::Expected object that contains its result; otherwise, returns a TRAP::Expected object that contains a copy of the contained expected value (obtained from operator).
- Parameters:
f – A suitable function or Callable object whose call signature returns a non-reference type.
- Returns:
A TRAP::Expected object containing either the result of f or an expected value, as described above.
Friends
-
template<typename U, typename E2>
inline friend constexpr bool operator==(const Expected &lhs, const Expected<U, E2> &rhs)# Performs comparison operations on expected objects. Compares two expected objects. The objects compare equal if and only if lhs.HasValue() and rhs.HasValue() are equal, and the contained values are equal.
-
template<typename U>
inline friend constexpr bool operator==(const Expected &lhs, const U &rhs)# Performs comparison operations on expected objects. Compares expected object with a value. The objects compare equal if and only if rhs contains an expected value, and the contained value is equal to rhs.
- Parameters:
lhs – Expected object to compare.
rhs – Value to compare to the expected value contained in x.
- Returns:
Returns lhs.HasValue() && static_cast<bool>(*lhs == rhs).
-
template<typename E2>
inline friend constexpr bool operator==(const Expected &lhs, const Unexpected<E2> &rhs)# Performs comparison operations on expected objects. Compares expected object with an unexpected value. The objects compare equal if and only if lhs contains an unexpected value, and the contained value is equal to rhs.Error().
- Parameters:
lhs – Expected object to compare.
rhs – Value to compare to the unexpected value contained in rhs.
- Returns:
Returns !lhs.HasValue() && static_cast<bool>(lhs.Error() == rhs.Error()).