Skip to content

cvw::expected<void, E>

Specialization of expected for void value type. More...

#include <expected.hpp>

Public Types

Name
using voidvalue_type
Value type alias.
using Eerror_type
Error type alias.
using unexpected<E>unexpected_type
Unexpected type alias.

Public Functions

Name
constexprexpected()
Default constructor. Creates expected in success state.
expected(constexpected & o)
Copy constructor.
expected(expected && o)
Move constructor.
template <typenameG =E&gt;
constexpr
expected(constunexpected<G> & u)
Constructor from unexpected.
template <typenameG =E&gt;
constexpr
expected(unexpected<G> && u)
Constructor from unexpected rvalue.
constexprexpected(std::in_place_t )
In-place constructor for success state.
template <typename... Args&gt;
constexpr
expected(unexpect_t , Args &&... args)
Constructor for in-place error construction.
~expected()
Destructor.
expected &operator=(constexpected & o)
Copy assignment operator.
constexprboolhas_value() const
Checks if the expected is in success state.
constexproperator bool() const
Boolean conversion operator.
constexprvoidvalue() const
Returns void if in success state.
constexprE &error()
Returns the contained error.
constexprconstE &error() const
Returns the contained error (const lvalue).
constexprE &&error()
Returns the contained error (rvalue).
constexprconstE &&error() const
Returns the contained error (const rvalue).
template <typenameF &gt;
auto
and_then(F && f)
Monadic operation: chains if in success state.
template <typenameF &gt;
auto
and_then(F && f)
Monadic operation: chains if in success state (rvalue).
template <typenameF &gt;
auto
transform(F && f)
Monadic operation: transforms the success state.
template <typenameF &gt;
auto
transform(F && f)
Monadic operation: transforms the success state (rvalue).

Detailed Description

cpp
template <typenameE>
class cvw::expected<void, E>;

Specialization of expected for void value type.

Template Parameters:

  • E Error type.

This specialization represents operations that may fail but do not produce a value on success.

Public Types Documentation

using value_type

cpp
using cvw::expected<void, E>::value_type =  void;

Value type alias.

using error_type

cpp
using cvw::expected<void, E>::error_type =  E;

Error type alias.

using unexpected_type

cpp
using cvw::expected<void, E>::unexpected_type =  unexpected<E>;

Unexpected type alias.

Public Functions Documentation

function expected

cpp
inline constexpr expected()

Default constructor. Creates expected in success state.

Exceptions:

  • None.

function expected

cpp
inline expected(
    constexpected & o
)

Copy constructor.

Parameters:

  • o Expected to copy from.

Exceptions:

  • May throw if E copy constructor throws.

function expected

cpp
inline expected(
    expected && o
)

Move constructor.

Parameters:

  • o Expected to move from.

Exceptions:

  • May throw if E move constructor throws.

function expected

cpp
template <typenameG  =E>
inline constexpr expected(
    constunexpected<G> & u
)

Constructor from unexpected.

Parameters:

  • u Unexpected value containing error.

Exceptions:

  • May throw if E constructor throws.

Template Parameters:

  • G Forwarded error type.

function expected

cpp
template <typenameG  =E>
inline constexpr expected(
    unexpected<G> && u
)

Constructor from unexpected rvalue.

Parameters:

  • u Unexpected value containing error.

Exceptions:

  • May throw if E constructor throws.

Template Parameters:

  • G Forwarded error type.

function expected

cpp
inline explicit constexpr expected(
    std::in_place_t 
)

In-place constructor for success state.

Exceptions:

  • None.

function expected

cpp
template <typename... Args>
inline explicit constexpr expected(
    unexpect_t ,
    Args &&... args
)

Constructor for in-place error construction.

Parameters:

  • args Arguments to forward to E constructor.

Exceptions:

  • May throw if E constructor throws.

Template Parameters:

  • Args Constructor argument types.

function ~expected

cpp
inline ~expected()

Destructor.

Exceptions:

  • None.

function operator=

cpp
inline expected & operator=(
    constexpected & o
)

Copy assignment operator.

Parameters:

  • o Expected to copy from.

Exceptions:

  • May throw if E assignment or construction throws.

Return: Reference to this expected.

function has_value

cpp
inline constexprbool has_value() const

Checks if the expected is in success state.

Exceptions:

  • None.

Return: true if in success state, false if in error state.

function operator bool

cpp
inline explicit constexpr operator bool() const

Boolean conversion operator.

Exceptions:

  • None.

Return: true if in success state, false if in error state.

function value

cpp
inline constexprvoid value() const

Returns void if in success state.

Exceptions:

Warning: Throws bad_expected_access if this expected contains an error.

function error

cpp
inline constexprE & error()

Returns the contained error.

Exceptions:

  • None.

Return: Reference to the contained error.

Warning: The error is only valid if has_value() returns false.

function error

cpp
inline constexprconstE & error() const

Returns the contained error (const lvalue).

Exceptions:

  • None.

Return: Const reference to the contained error.

Warning: The error is only valid if has_value() returns false.

function error

cpp
inline constexprE && error()

Returns the contained error (rvalue).

Exceptions:

  • None.

Return: Rvalue reference to the contained error.

Warning: The error is only valid if has_value() returns false.

function error

cpp
inline constexprconstE && error() const

Returns the contained error (const rvalue).

Exceptions:

  • None.

Return: Const rvalue reference to the contained error.

Warning: The error is only valid if has_value() returns false.

function and_then

cpp
template <typenameF>
inline auto and_then(
    F && f
)

Monadic operation: chains if in success state.

Parameters:

  • f Function to call if in success state.

Exceptions:

  • None.

Template Parameters:

  • F Callable type.

Return: Result of f() or error.

function and_then

cpp
template <typenameF>
inline auto and_then(
    F && f
)

Monadic operation: chains if in success state (rvalue).

Parameters:

  • f Function to call if in success state.

Exceptions:

  • None.

Template Parameters:

  • F Callable type.

Return: Result of f() or error.

function transform

cpp
template <typenameF>
inline auto transform(
    F && f
)

Monadic operation: transforms the success state.

Parameters:

  • f Function to apply.

Exceptions:

  • None.

Template Parameters:

  • F Callable type.

Return: expected with transformed value or error.

function transform

cpp
template <typenameF>
inline auto transform(
    F && f
)

Monadic operation: transforms the success state (rvalue).

Parameters:

  • f Function to apply.

Exceptions:

  • None.

Template Parameters:

  • F Callable type.

Return: expected with transformed value or error.


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

Built with VitePress