Skip to content

cvw::unexpected

Wrapper type for constructing expected objects in error state. More...

#include <expected.hpp>

Public Functions

Name
unexpected() =delete
Deleted default constructor.
template <typenameErr =E&gt;
constexpr
unexpected(Err && e)
Constructs unexpected from an error value.
template <typename... Args&gt;
constexpr
unexpected(std::in_place_t , Args &&... args)
Constructs unexpected in-place with arguments.
template <typenameU ,typename... Args&gt;
constexpr
unexpected(std::in_place_t , std::initializer_list<U> il, Args &&... args)
Constructs unexpected in-place with initializer list.
constexprconstE &error() const
Returns const reference to the error.
constexprE &error()
Returns reference to the error.
constexprconstE &&error() const
Returns const rvalue reference to the error.
constexprE &&error()
Returns rvalue reference to the error.
voidswap(unexpected & other)
Swaps the error with another unexpected.

Friends

Name
constexprbooloperator==(constunexpected & a, constunexpected<E2> & b)
Compares two unexpected objects for equality.

Detailed Description

cpp
template <typenameE>
class cvw::unexpected;

Wrapper type for constructing expected objects in error state.

Template Parameters:

  • E Error type to wrap.

Public Functions Documentation

function unexpected

cpp
unexpected() =delete

Deleted default constructor.

function unexpected

cpp
template <typenameErr  =E>
inline explicit constexpr unexpected(
    Err && e
)

Constructs unexpected from an error value.

Parameters:

  • e Error value to wrap.

Template Parameters:

  • Err Forwarded error type.

function unexpected

cpp
template <typename... Args>
inline explicit constexpr unexpected(
    std::in_place_t ,
    Args &&... args
)

Constructs unexpected in-place with arguments.

Parameters:

  • args Arguments to forward to E constructor.

Template Parameters:

  • Args Constructor argument types.

function unexpected

cpp
template <typenameU ,
typename... Args>
inline explicit constexpr unexpected(
    std::in_place_t ,
    std::initializer_list< U > il,
    Args &&... args
)

Constructs unexpected in-place with initializer list.

Parameters:

  • il Initializer list.
  • args Additional arguments.

Template Parameters:

  • U Element type of initializer list.
  • Args Constructor argument types.

function error

cpp
inline constexprconstE & error() const

Returns const reference to the error.

Exceptions:

  • None.

Return: Const reference to the error.

function error

cpp
inline constexprE & error()

Returns reference to the error.

Exceptions:

  • None.

Return: Reference to the error.

function error

cpp
inline constexprconstE && error() const

Returns const rvalue reference to the error.

Exceptions:

  • None.

Return: Const rvalue reference to the error.

function error

cpp
inline constexprE && error()

Returns rvalue reference to the error.

Exceptions:

  • None.

Return: Rvalue reference to the error.

function swap

cpp
inline void swap(
    unexpected & other
)

Swaps the error with another unexpected.

Parameters:

  • other Other unexpected to swap with.

Exceptions:

  • None if E is nothrow swappable.

Since: 0.1

Note: None.

Warning: None.

Friends

friend operator==

cpp
friend constexprbool operator==(
    constunexpected & a,

    constunexpected<E2> & b
);

Compares two unexpected objects for equality.

Parameters:

  • a First unexpected.
  • b Second unexpected.

Exceptions:

  • None.

Template Parameters:

  • E2 Error type of the other unexpected.

Return: true if errors are equal, false otherwise.


Updated on 2026-05-17 at 13:22:38 +0000

Built with VitePress