Optional Objects

Synopsis

Declared in <beman/optional/optional.hpp>

template<class T>
class optional;

Type Aliases

Name

Description

const_iterator

Type alias for the const iterator type of the optional.

iterator

Type alias for the iterator type of the optional.

value_type

Type alias for the value type contained in the optional.

Member Functions

Name

Description

optional [constructor]

Constructors

~optional [destructor]

Destructors

operator=

Assignment operators

and_then

Applies a function to the contained value if there is one.

begin

begin overloads

emplace

emplace overloads

end

end overloads

has_value

Returns whether or not the optional has a value.

operator*

Returns a reference to the contained value.

operator‐>

Returns a pointer to the contained value.

or_else

or_else overloads

reset

Resets the optional to an empty state, destroying the contained value if there is one.

swap

Swaps this optional with the other.

transform

Returns an optional containing the result of applying f to the contained value, or an empty optional if there is no contained value.

value

Returns a reference to the contained value.

value_or

Returns the contained value if there is one, otherwise returns u.

operator bool

Converts the optional to a boolean indicating whether it has a value.

Data Members

Name

Description

_ [variant member]

The empty state of the optional.

value_ [variant member]

The contained value of the optional.

Specializations

Name

Description

optional<T&>

A specialization of optional for references.

Friends

Name

Description

beman::optional::optional

Optional Objects

Non-Member Functions

Name

Description

make_optional

Creates an optional<T> constructing the value in‐place from the given arguments.

make_optional

Creates an optional holding a decayed copy of the given value.

make_optional

Creates an optional<T> constructing the value in‐place from an initializer list and arguments.

operator!=

Compares an optional against a value for inequality.

operator!=

Compares two optionals for inequality.

operator<

Orders an optional before a value with less‐than.

operator<

Orders two optionals with less‐than.

operator<=

Orders two optionals with less‐than‐or‐equal.

operator<=

Orders an optional before or equal to a value.

operator<=>

Three‐way comparison of an optional against nullopt.

operator<=>

Three‐way comparison of an optional against a value.

operator<=>

Three‐way comparison of two optionals.

operator==

Compares an optional against nullopt.

operator==

Compares two optionals for equality.

operator==

Compares an engaged optional's value against a value for equality.

operator>

Orders two optionals with greater‐than.

operator>

Orders an optional after a value with greater‐than.

operator>=

Orders an optional after or equal to a value.

operator>=

Orders two optionals with greater‐than‐or‐equal.

swap

Swap

Created with MrDocs