Template Class Unexpected#
Defined in File Expected.h
Class Documentation#
-
template<typename E>
class Unexpected# The class template TRAP::Unexpected represents an unexpected value stored in TRAP::Expected. In particular, TRAP::Expected has constructors with TRAP::Unexpected as a single argument, which creates an expected object that contains an unexpected value.
A program is ill-formed if it instantiates an unexpected with a non-object type, an array type, a specialization of TRAP::Unexpected, or a cv-qualified type.
- Template Parameters:
E – The type of the unexpected value. The type must not be an array type, a non-object type, a specialization of TRAP::Unexpected, or a cv-qualified type.
Public Functions
-
consteval Unexpected() = delete#
Constructor. Constructs a TRAP::Unexpected object.
-
constexpr ~Unexpected() = default#
Destructor. Destroys a TRAP::Unexpected object.
-
constexpr Unexpected(const Unexpected&) = default#
Copy constructor. Constructs a TRAP::Unexpected object. Copies the stored value.
-
constexpr Unexpected(Unexpected&&) = default#
Move constructor. Constructs a TRAP::Unexpected object. Moves the stored value.
-
constexpr Unexpected &operator=(const Unexpected&) = default#
Copy assignment operator.
- Returns:
*this.
-
constexpr Unexpected &operator=(Unexpected&&) = default#
Move assignment operator.
- Returns:
*this.
-
template<typename Err = E>
inline explicit constexpr Unexpected(Err &&e) noexcept(std::is_nothrow_constructible_v<E, Err>)# Constructs a TRAP::Unexpected object. Constructs the stored value, as if by direct-initializing a value of type E from std::forward<Err>(e).
- Parameters:
e – Value with which to initialize the contained value.
-
template<typename ...Args>
inline explicit constexpr Unexpected(const std::in_place_t _, Args&&... args) noexcept(std::is_nothrow_constructible_v<E, Args...>)# Constructs a TRAP::Unexpected object. Constructs the stored value, as if by direct-initializing a value of type E from the arguments std::forward<Args>(args)….
- Parameters:
args – Arguments with which to initialize the contained value.
-
template<typename U, typename ...Args>
inline explicit constexpr Unexpected(const std::in_place_t _, std::initializer_list<U> il, Args&&... args)# Constructs a TRAP::Unexpected object. Constructs the stored value, as if by direct-initializing a value of type E from the arguments il, std::forward<Args>(args)….
- Parameters:
il – Initializer list with which to initialize the contained value.
args – Arguments with which to initialize the contained value.
-
inline constexpr const E &Error() const & noexcept#
Retrieve a reference to the stored value.
- Returns:
Reference to the stored value.
-
inline constexpr E &Error() & noexcept#
Retrieve a reference to the stored value.
- Returns:
Reference to the stored value.
-
inline constexpr const E &&Error() const && noexcept#
Retrieve a reference to the stored value.
- Returns:
Reference to the stored value.
-
inline constexpr E &&Error() && noexcept#
Retrieve a reference to the stored value.
- Returns:
Reference to the stored value.
-
inline constexpr void Swap(Unexpected &other) noexcept(std::is_nothrow_swappable_v<E>)#
Swaps the stored values, as if by using std::swap; swap(Error(), other.Error());. The program is ill-formed if std::is_swappable_v<E> is false.
Friends
-
template<typename E2>
inline friend constexpr bool operator==(const Unexpected &x, const TRAP::Unexpected<E2> &y)# Compares the stored values, as if by return x.Error() == y.Error(). If the expression x.Error() == e.Error() is not well-formed, or if its result is not convertible to bool, the program is ill-formed.
Note
This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when TRAP::Unexpected<E> is an associated class of the arguments.
-
template<typename E2>
inline friend constexpr bool operator!=(const Unexpected &x, const TRAP::Unexpected<E2> &y)# Compares the stored values, as if by return x.Error() != y.Error(). If the expression x.Error() != e.Error() is not well-formed, or if its result is not convertible to bool, the program is ill-formed.
Note
This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when TRAP::Unexpected<E> is an associated class of the arguments.
-
inline friend constexpr void swap(Unexpected &lhs, Unexpected &rhs) noexcept(noexcept(lhs.Swap(rhs)))#
Equivalent to x.Swap(y);.
Note
This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when TRAP::Unexpected<E> is an associated class of the arguments.