sumty
0.1.0
Better sum types for C++
|
Type that either contains some value or none. More...
#include <sumty/option.hpp>
Public Types | |
using | value_type = ... |
using | reference = ... |
using | const_reference = ... |
using | rvalue_reference = ... |
using | const_rvalue_reference = ... |
using | pointer = ... |
using | const_pointer = ... |
Public Member Functions | |
constexpr | option () noexcept |
Default constructor. More... | |
constexpr | option (const option &) CONDITIONALLY_NOEXCEPT |
Copy constructor. More... | |
constexpr | option (option &&) CONDITIONALLY_NOEXCEPT |
Move constructor. More... | |
constexpr | option ([[maybe_unused]] none_t null) noexcept |
None constructor. More... | |
constexpr | option ([[maybe_unused]] std::nullopt_t null) noexcept |
std::nullopt constructor More... | |
constexpr | option ([[maybe_unused]] std::nullptr_t null) noexcept |
nullptr constructor More... | |
template<typename U > | |
constexpr CONDITIONALLY_EXPLICIT | option (U *ptr) noexcept |
Pointer constructor. More... | |
template<typename U > | |
constexpr CONDITIONALLY_EXPLICIT | option (const option< U > &other) |
Converting copy constructor. More... | |
template<typename U > | |
constexpr CONDITIONALLY_EXPLICIT | option (option< U > &&other) |
Converting move constructor. More... | |
template<typename... Args> | |
constexpr CONDITIONALLY_EXPLICIT | option ([[maybe_unused]] std::in_place_t inplace, Args &&... args) |
Emplacement constructor. More... | |
template<typename U , typename... Args> | |
constexpr | option ([[maybe_unused]] std::in_place_t inplace, std::initializer_list< U > init, Args &&... args) |
Emplacement constructor with initializer list. More... | |
template<typename U > | |
constexpr CONDITIONALLY_EXPLICIT | option (U &&value) |
Forwarding constructor. More... | |
constexpr | ~option () CONDITIONALLY_NOEXCEPT |
Destructor. More... | |
constexpr option & | operator= (const option &) CONDITIONALLY_NOEXCEPT |
Copy assignment operator. More... | |
constexpr option & | operator= (option &&) CONDITIONALLY_NOEXCEPT |
Move assignment operator. More... | |
constexpr option & | operator= ([[maybe_unused]] none_t null) CONDTIONALLY_NOEXCEPT |
none assignment operator More... | |
constexpr option & | operator= ([[maybe_unused]] std::nullopt_t null) CONDITIONALLY_NOEXCEPT |
std::nullopt assignment operator More... | |
constexpr option & | operator= ([[maybe_unused]] std::nullptr_t null) noexcept |
nullptr assignment operator More... | |
template<typename U > | |
constexpr option & | operator= (U &&value) |
Value assignment operator. More... | |
template<typename U > | |
constexpr option & | operator= (U *ptr) noexcept |
Pointer assignment operator. More... | |
template<typename U > | |
constexpr option & | operator= (const option< U > &value) |
Converting copy assignment operator. More... | |
template<typename U > | |
constexpr option & | operator= (option< U > &&value) |
Converting move assignment operator. More... | |
constexpr | operator bool () const noexcept |
Implicit conversion to bool . More... | |
template<typename U > | |
constexpr CONDITIONALLY_EXPLICIT | operator U* () const noexcept |
Conversion to raw pointer. More... | |
constexpr bool | has_value () const noexcept |
Returns true if the option contains a value. More... | |
constexpr bool | is_some () const noexcept |
Returns true if the option contains a value. More... | |
constexpr bool | is_none () const noexcept |
Returns true if the options does not contain a value. More... | |
constexpr reference | operator* () &noexcept |
Accesses the value contained in the option. More... | |
constexpr const_reference | operator* () const &noexcept |
Accesses the value contained in the option. More... | |
constexpr rvalue_reference | operator* () && |
Accesses the value contained in the option. More... | |
constexpr const_rvalue_reference | operator* () const && |
Accesses the value contained in the option. More... | |
constexpr pointer | operator-> () noexcept |
Accesses members of the value contained in the option. More... | |
constexpr const_pointer | operator-> () const noexcept |
Accesses members of the value contained in the option. More... | |
constexpr reference | value () & |
Accesses the value contained in the option. More... | |
constexpr const_reference | value () const & |
Accesses the value contained in the option. More... | |
constexpr rvalue_reference | value () && |
Accesses the value contained in the option. More... | |
constexpr rvalue_reference | value () const && |
Accesses the value contained in the option. More... | |
template<typename U > | |
constexpr value_type | value_or (U &&default_value) const & |
Gets the option value with a default used for none . More... | |
template<typename U > | |
constexpr value_type | value_or (U &&default_value) && |
Gets the option value with a default used for none . More... | |
template<typename F > | |
constexpr value_type | value_or_else (F &&f) const & |
Gets the option value with a default used for none . More... | |
template<typename F > | |
constexpr value_type | value_or_else (F &&f) && |
Gets the option value with a default used for none . More... | |
constexpr reference | some () & |
Accesses the value contained in the option. More... | |
constexpr const_reference | some () const & |
Accesses the value contained in the option. More... | |
constexpr rvalue_reference | some () && |
Accesses the value contained in the option. More... | |
constexpr rvalue_reference | some () const && |
Accesses the value contained in the option. More... | |
template<typename U > | |
constexpr value_type | some_or (U &&default_value) const & |
Gets the option value with a default used for none . More... | |
template<typename U > | |
constexpr value_type | some_or (U &&default_value) && |
Gets the option value with a default used for none . More... | |
template<typename F > | |
constexpr value_type | some_or_else (F &&f) const & |
Gets the option value with a default used for none . More... | |
template<typename F > | |
constexpr value_type | some_or_else (F &&f) && |
Gets the option value with a default used for none . More... | |
template<typename E > | |
constexpr result< T, std::remove_cvref_t< E > > | ok_or (E &&err) const & |
Converts an option to a result. More... | |
template<typename E > | |
constexpr result< T, std::remove_cvref_t< E > > | ok_or (E &&err) && |
Converts an option to a result. More... | |
template<typename E > | |
constexpr result< T, E > | ok_or (const result< never, E > &err) const & |
Converts an option to a result. More... | |
template<typename E > | |
constexpr result< T, E > | ok_or (const result< never, E > &err) && |
Converts an option to a result. More... | |
template<typename E > | |
constexpr result< T, E > | ok_or (result< never, E > &&err) const & |
Converts an option to a result. More... | |
template<typename E > | |
constexpr result< T, E > | ok_or (result< never, E > &&err) && |
Converts an option to a result. More... | |
template<typename F > | |
constexpr result< T, std::invoke_result_t< F > > | ok_or_else (F &&f) const & |
Converts an option to a result. More... | |
template<typename F > | |
constexpr result< T, std::invoke_result_t< F > > | ok_or_else (F &&f) && |
Converts an option to a result. More... | |
template<typename U > | |
constexpr result< std::remove_cvref_t< U >, T > | error_or (U &&value) const & |
Converts an option to a result. More... | |
template<typename U > | |
constexpr result< std::remove_cvref_t< U >, T > | error_or (U &&value) && |
Converts an option to a result. More... | |
template<typename U > | |
constexpr result< U, T > | error_or (const result< U, never > &value) const & |
Converts an option to a result. More... | |
template<typename U > | |
constexpr result< U, T > | error_or (const result< U, never > &value) && |
Converts an option to a result. More... | |
template<typename U > | |
constexpr result< U, T > | error_or (result< U, never > &&value) const & |
Converts an option to a result. More... | |
template<typename U > | |
constexpr result< U, T > | error_or (result< U, never > &&value) && |
Converts an option to a result. More... | |
template<typename F > | |
constexpr result< std::invoke_result_t< F >, T > | error_or_else (F &&f) const & |
Converts an option to a result. More... | |
template<typename F > | |
constexpr result< std::invoke_result_t< F >, T > | error_or_else (F &&f) && |
Converts an option to a result. More... | |
constexpr option< reference > | ref () noexcept |
Converts an option into an option of a reference. More... | |
constexpr option< const_reference > | ref () const noexcept |
Converts an option into an option of a reference. More... | |
constexpr option< const_reference > | cref () const noexcept |
Converts an option into an option of a reference. More... | |
template<typename F > | |
constexpr auto | and_then (F &&f) & |
Applies a callable to the contents of an option. More... | |
template<typename F > | |
constexpr auto | and_then (F &&f) const & |
Applies a callable to the contents of an option. More... | |
template<typename F > | |
constexpr auto | and_then (F &&f) && |
Applies a callable to the contents of an option. More... | |
template<typename F > | |
constexpr auto | and_then (F &&f) const && |
Applies a callable to the contents of an option. More... | |
template<typename F > | |
constexpr auto | transform (F &&f) & |
Performs a transformation on the content of an option. More... | |
template<typename F > | |
constexpr auto | transform (F &&f) const & |
Performs a transformation on the content of an option. More... | |
template<typename F > | |
constexpr auto | transform (F &&f) && |
Performs a transformation on the content of an option. More... | |
template<typename F > | |
constexpr auto | transform (F &&f) const && |
Performs a transformation on the content of an option. More... | |
template<typename F > | |
constexpr auto | map (F &&f) & |
Performs a transformation on the content of an option. More... | |
template<typename F > | |
constexpr auto | map (F &&f) const & |
Performs a transformation on the content of an option. More... | |
template<typename F > | |
constexpr auto | map (F &&f) && |
Performs a transformation on the content of an option. More... | |
template<typename F > | |
constexpr auto | map (F &&f) const && |
Performs a transformation on the content of an option. More... | |
template<typename F > | |
constexpr option | or_else (F &&f) const & |
Returns the result of f if the option is none . More... | |
template<typename F > | |
constexpr option | or_else (F &&f) && |
Returns the result of f if the option is none . More... | |
constexpr T | flatten () const & |
Converts option<option<T>> to option<T> More... | |
constexpr T | flatten () && |
Converts option<option<T>> to option<T> More... | |
constexpr auto | flatten_all () const & |
Converts nested option types into a single option. More... | |
constexpr auto | flatten_all () && |
Converts nested option types into a single option. More... | |
template<typename Pred > | |
constexpr option | filter (Pred &&pred) const & |
Filters the option based on a predicate. More... | |
template<typename Pred > | |
constexpr option | filter (Pred &&pred) && |
Filters the option based on a predicate. More... | |
constexpr auto | transpose () const & |
Converts option<result<T, E>> into result<option<T>, E> More... | |
constexpr auto | transpose () && |
Converts option<result<T, E>> into result<option<T>, E> More... | |
template<typename V > | |
constexpr DEDUCED | visit (V &&visitor) & |
Calls a visitor callable with the contained value or void . More... | |
template<typename V > | |
constexpr DEDUCED | visit (V &&visitor) const & |
Calls a visitor callable with the contained value or void . More... | |
template<typename V > | |
constexpr DEDUCED | visit (V &&visitor) && |
Calls a visitor callable with the contained value or void . More... | |
template<typename V > | |
constexpr DEDUCED | visit (V &&visitor) const && |
Calls a visitor callable with the contained value or void . More... | |
template<typename V > | |
constexpr DEDUCED | visit_informed (V &&visitor) & |
Calls a visitor callable with the contained value and meta data. More... | |
template<typename V > | |
constexpr DEDUCED | visit_informed (V &&visitor) const & |
Calls a visitor callable with the contained value and meta data. More... | |
template<typename V > | |
constexpr DEDUCED | visit_informed (V &&visitor) && |
Calls a visitor callable with the contained value and meta data. More... | |
template<typename V > | |
constexpr DEDUCED | visit_informed (V &&visitor) const && |
Calls a visitor callable with the contained value and meta data. More... | |
constexpr void | swap (option &other) CONDITIONALLY_NOEXCEPT |
Swaps two option instances. More... | |
constexpr void | reset () noexcept |
Sets the option to none . More... | |
template<typename... Args> | |
constexpr reference | emplace (Args &&... args) |
Constructs a new value in place into the option. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<size_t IDX, typename T > | |
constexpr REFERENCE | get (option< T > &opt) |
Gets an option value by index, as if it were a variant. More... | |
template<size_t IDX, typename T > | |
constexpr CONST_REFERENCE | get (const option< T > &opt) |
Gets an option value by index, as if it were a variant. More... | |
template<size_t IDX, typename T > | |
constexpr RVALUE_REFERENCE | get (option< T > &&opt) |
Gets an option value by index, as if it were a variant. More... | |
template<size_t IDX, typename T > | |
constexpr CONST_RVALUE_REFERENCE | get (const option< T > &&opt) |
Gets an option value by index, as if it were a variant. More... | |
template<typename T , typename U > | |
constexpr REFERENCE | get (option< U > &opt) |
Gets an option value by type, as if it were a variant. More... | |
template<typename T , typename U > | |
constexpr CONST_REFERENCE | get (const option< U > &opt) |
Gets an option value by type, as if it were a variant. More... | |
template<typename T , typename U > | |
constexpr RVALUE_REFERENCE | get (option< U > &&opt) |
Gets an option value by type, as if it were a variant. More... | |
template<typename T , typename U > | |
constexpr CONST_RVALUE_REFERENCE | get (const option< U > &&opt) |
Gets an option value by type, as if it were a variant. More... | |
template<typename T , typename U > | |
constexpr bool | operator== (const option< T > &lhs, const option< U > &rhs) |
Tests two option instances for equality. More... | |
template<typename T , typename U > | |
constexpr bool | operator!= (const option< T > &lhs, const option< U > &rhs) |
Tests two option instances for inequality. More... | |
template<typename T , typename U > | |
constexpr bool | operator< (const option< T > &lhs, const option< U > &rhs) |
Compares two option instances. More... | |
template<typename T , typename U > | |
constexpr bool | operator> (const option< T > &lhs, const option< U > &rhs) |
Compares two option instances. More... | |
template<typename T , typename U > | |
constexpr bool | operator<= (const option< T > &lhs, const option< U > &rhs) |
Compares two option instances. More... | |
template<typename T , typename U > | |
constexpr bool | operator>= (const option< T > &lhs, const option< U > &rhs) |
Compares two option instances. More... | |
template<typename T , typename U > | |
constexpr auto | operator (const option< T > &lhs, const option< U > &rhs) |
Compares two option instances. More... | |
template<typename T , typename U > | |
constexpr bool | operator== (const option< T > &lhs, const U &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator== (const U &lhs, const option< T > &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator!= (const option< T > &lhs, const U &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator!= (const U &lhs, const option< T > &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator< (const option< T > &lhs, const U &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator< (const U &lhs, const option< T > &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator> (const option< T > &lhs, const U &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator> (const U &lhs, const option< T > &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator<= (const option< T > &lhs, const U &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator<= (const U &lhs, const option< T > &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator>= (const option< T > &lhs, const U &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr bool | operator>= (const U &lhs, const option< T > &rhs) |
Compares an option with a value. More... | |
template<typename T , typename U > | |
constexpr auto | operator (const option< T > &lhs, const U &rhs) |
Compares an option with a value. More... | |
template<typename T > | |
constexpr bool | operator== (const option< T > &lhs,[[maybe_unused]] none_t rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator== ([[maybe_unused]] none_t lhs, const option< T > &rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator!= (const option< T > &lhs,[[maybe_unused]] none_t rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator!= ([[maybe_unused]] none_t lhs, const option< T > &rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator< ([[maybe_unused]] const option< T > &lhs,[[maybe_unused]] none_t rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator< ([[maybe_unused]] none_t lhs, const option< T > &rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator> (const option< T > &lhs,[[maybe_unused]] none_t rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator> ([[maybe_unused]] none_t lhs,[[maybe_unused]] const option< T > &rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator<= (const option< T > &lhs,[[maybe_unused]] none_t rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator<= ([[maybe_unused]] none_t lhs,[[maybe_unused]] const option< T > &rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator>= ([[maybe_unused]] const option< T > &lhs,[[maybe_unused]] none_t rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator>= ([[maybe_unused]] none_t lhs, const option< T > &rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr std::strong_ordering | operator (const option< T > &lhs,[[maybe_unused]] none_t rhs) |
Compares an option with none . More... | |
template<typename T > | |
constexpr bool | operator== (const option< T > &lhs,[[maybe_unused]] std::nullopt_t rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator== ([[maybe_unused]] std::nullopt_t lhs, const option< T > &rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator!= (const option< T > &lhs,[[maybe_unused]] std::nullopt_t rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator!= ([[maybe_unused]] std::nullopt_t lhs, const option< T > &rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator< ([[maybe_unused]] const option< T > &lhs,[[maybe_unused]] std::nullopt_t rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator< ([[maybe_unused]] std::nullopt_t lhs, const option< T > &rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator> (const option< T > &lhs,[[maybe_unused]] std::nullopt_t rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator> ([[maybe_unused]] std::nullopt_t lhs,[[maybe_unused]] const option< T > &rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator<= (const option< T > &lhs,[[maybe_unused]] std::nullopt_t rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator<= ([[maybe_unused]] std::nullopt_t lhs,[[maybe_unused]] const option< T > &rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator>= ([[maybe_unused]] const option< T > &lhs,[[maybe_unused]] std::nullopt_t rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator>= ([[maybe_unused]] std::nullopt_t lhs, const option< T > &rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr std::strong_ordering | operator (const option< T > &lhs,[[maybe_unused]] std::nullopt_t rhs) |
Compares an option with std::nullopt . More... | |
template<typename T > | |
constexpr bool | operator== (const option< T > &lhs,[[maybe_unused]] std::nullptr_t rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator== ([[maybe_unused]] std::nullptr_t lhs, const option< T > &rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator!= (const option< T > &lhs,[[maybe_unused]] std::nullptr_t rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator!= ([[maybe_unused]] std::nullptr_t lhs, const option< T > &rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator< ([[maybe_unused]] const option< T > &lhs,[[maybe_unused]] std::nullptr_t rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator< ([[maybe_unused]] std::nullptr_t lhs, const option< T > &rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator> (const option< T > &lhs,[[maybe_unused]] std::nullptr_t rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator> ([[maybe_unused]] std::nullptr_t lhs,[[maybe_unused]] const option< T > &rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator<= (const option< T > &lhs,[[maybe_unused]] std::nullptr_t rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator<= ([[maybe_unused]] std::nullptr_t lhs,[[maybe_unused]] const option< T > &rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator>= ([[maybe_unused]] const option< T > &lhs,[[maybe_unused]] std::nullptr_t rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr bool | operator>= ([[maybe_unused]] std::nullptr_t lhs, const option< T > &rhs) |
Compares an option with nullptr . More... | |
template<typename T > | |
constexpr std::strong_ordering | operator (const option< T > &lhs,[[maybe_unused]] std::nullptr_t rhs) |
Compares an option with nullptr . More... | |
template<typename T , typename U > | |
constexpr bool | operator== (const option< T > &lhs, const U *rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator!= (const option< T > &lhs, const U *rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator< (const option< T > &lhs, const U *rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator> (const option< T > &lhs, const U *rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator<= (const option< T > &lhs, const U *rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator>= (const option< T > &lhs, const U *rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator== (const U *lhs, const option< T > &rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator!= (const U *lhs, const option< T > &rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator< (const U *lhs, const option< T > &rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator> (const U *lhs, const option< T > &rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator<= (const U *lhs, const option< T > &rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr bool | operator>= (const U *lhs, const option< T > &rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename U > | |
constexpr auto | operator (const option< T > &lhs, const U *rhs) |
Compares an option with a pointer. More... | |
template<typename T , typename... Args> | |
constexpr option< T > | some (Args &&... args) |
Constructs an option that contains a value. More... | |
template<typename T , typename U , typename... Args> | |
constexpr option< T > | some (std::initializer_list< U > ilist, Args &&... args) |
Constructs an option that contains a value. More... | |
template<typename T > | |
constexpr void | swap (option< T > &a, option< T > &b) CONDITIONALLY_NOEXCEPT |
Swaps two option instances. More... | |
![]() | |
constexpr REFERENCE | get (variant< T... > &v) |
Gets a variant alternative by index. More... | |
constexpr CONST_REFERENCE | get (const variant< T... > &v) |
Gets a variant alternative by index. More... | |
constexpr RVALUE_REFERENCE | get (variant< T... > &&v) |
Gets a variant alternative by index. More... | |
constexpr CONST_RVALUE_REFERENCE | get (const variant< T... > &&v) |
Gets a variant alternative by index. More... | |
constexpr REFERENCE | get (variant< U... > &v) |
Gets a variant alternative by type. More... | |
constexpr CONST_REFERENCE | get (const variant< U... > &v) |
Gets a variant alternative by type. More... | |
constexpr RVALUE_REFERENCE | get (variant< U... > &&v) |
Gets a variant alternative by type. More... | |
constexpr CONST_RVALUE_REFERENCE | get (const variant< U... > &&v) |
Gets a variant alternative by type. More... | |
constexpr POINTER | get_if (variant< T... > &v) noexcept |
Gets a variant alternative pointer by index if the variant holds it. More... | |
constexpr CONST_POINTER | get_if (const variant< T... > &v) noexcept |
Gets a variant alternative pointer by index if the variant holds it. More... | |
constexpr POINTER | get_if (variant< U... > &v) noexcept |
Gets a variant alternative pointer by type if the variant holds it. More... | |
constexpr CONST_POINTER | get_if (const variant< U... > &v) noexcept |
Gets a variant alternative pointer by type if the variant holds it. More... | |
constexpr bool | holds_alternative (const variant< U... > &v) noexcept |
Checks if a variant contains a particular alternative. More... | |
constexpr DEDUCED | visit (V &&visitor) |
Calls a visitor callable with the contained variant alternatives. More... | |
constexpr DEDUCED | visit (V &&visitor, T0 &&var0, TN &&... varn) |
Calls a visitor callable with the contained variant alternatives. More... | |
constexpr void | swap (variant< T... > &a, variant< T... > &b) CONDITIONALLY_NOEXCEPT |
Swaps two variant instances. More... | |
Type that either contains some value or none.
option is a reimplementation of std::optional
with several improvements. The key difference is that option can contain void
and references (lvalue and rvalue). option<void>
turns out to essentially be a bool
with the option interface, and option<T&>
behaves like non-owning, nullable smart pointer to T
.
Internally, option<T>
is represented as a variant<void, T>. Thus, option benefits from the size optimizations implemented by variant (see variant documentation for details). In particular, an option of void
or an empty type has the size of a bool
, and an option of an lvalue reference has the size of a raw pointer.
In practice, the benefit of option over std::optional
is that option can be used in more places, espeicially with generic code. A generic function (function template) that wants to be able to return a value of any type, but also allow that return value to be "null" or "none" can simply return a option<T>
, where T
is now allowed to be a reference or even void
.
An option of an lvalue reference can also be used as an alternative to raw pointers is many cases. option<T&>
communicates that the pointer is allowed to be null and that the pointer is non-owning. Depending on a project's C++ coding practices, option<T&>
may be preferable to T*
, for single-object pointers.
T | The possibly contained type |
|
constexprnoexcept |
Default constructor.
Initializes the option as none or null.
Copy constructor.
If the source option is not none, the new option is initialized with a value copy constructed from the value contained in the source option.
Move constructor.
If the source option is not none, the new option is initialized with a value move constructed from the value contained in the source option.
None constructor.
Initializes the option to the none
value. That is, the option will contain no value, and .has_value()
will return false
.
|
inlineconstexprnoexcept |
std::nullopt
constructor
Initializes the option to the none
value. That is, the option will contain no value, and .has_value()
will return false
.
|
inlineconstexprnoexcept |
nullptr
constructor
Initializes the option to the none
value. That is, the option will contain no value, and .has_value()
will return false
.
This constructor only participates in overload resolution if the contained value type is an lvalue reference, in which case the option behaves like a smart pointer.
|
inlineconstexprnoexcept |
Pointer constructor.
Initializes the option to contain a reference to the value that the pointer points to. If the pointer is null, the option will be none
. That is, the option will contain no value, and .has_value()
will return false
.
This constructor only participates in overload resolution if the contained value type is an lvalue reference, in which case the option behaves like a smart pointer.
This constructor is explicit
if the pointer is not implicitly convertible to T*
.
Converting copy constructor.
Initializes the option to contain the value of the source option where the contained value U
is converted to T
, as if by T{U_value}
. If the source option is none
, then the destination option will also be none
.
This constructor only participates in overload resolution if the value type T
of the destination option is constructible from the contained value of the source option U
.
This constructor is explicit
if U
is not implicitly convertible to T
.
Converting move constructor.
Initializes the option to contain the value of the source option where the contained value U
is moved and converted to T
, as if by T{std::move(U_value)}
. If the source option is none
, the the destination option will also be none
.
This constructor only participates in overload resolution if the value type T
of the destination option is convertible from the contained value of the source option U
.
This constructor is explicit
if U
is not implicitly convertible to T
.
|
inlineconstexpr |
Emplacement constructor.
The option is initialized such that it contains a value that is constructed in place from the forwarded arguments.
This constructor is explicit
if inplace
is the only argument.
|
inlineconstexpr |
Emplacement constructor with initializer list.
The option is initialized such that it contains a value that is constructed in place from the forwarded arguments.
|
inlineconstexpr |
Forwarding constructor.
The option is initialized such that it contains a value that is constructed in place with the passed value forwarded to the value type's constructor.
This constructor only participates in overload resolution if the contained value type is constructible from the passed value, the passed value is not of type std::in_place_t
, and either the the contained value type is not a scalar, or the forwarded value is not an option instance.
This constructor is explicit
if the passed value is not implicitly convertible to T
.
|
constexpr |
Destructor.
If the option is not none
, the contained value is destroy in place.
The destructor is noexcept
if the contained value type is nothrow destructible.
|
inlineconstexpr |
Applies a callable to the contents of an option.
If the option contains a value, the value is passed into the callable, and the invocation result is returned from this function. If the option is none
, the callable is not invoked and none
is returned.
This function only participates in overload resolution if the invocation result of the callable is an option.
f | Callable applied to the contained option value |
|
inlineconstexpr |
Applies a callable to the contents of an option.
If the option contains a value, the value is passed into the callable, and the invocation result is returned from this function. If the option is none
, the callable is not invoked and none
is returned.
This function only participates in overload resolution if the invocation result of the callable is an option.
f | Callable applied to the contained option value |
|
inlineconstexpr |
Applies a callable to the contents of an option.
If the option contains a value, the value is passed into the callable, and the invocation result is returned from this function. If the option is none
, the callable is not invoked and none
is returned.
This function only participates in overload resolution if the invocation result of the callable is an option.
f | Callable applied to the contained option value |
|
inlineconstexpr |
Applies a callable to the contents of an option.
If the option contains a value, the value is passed into the callable, and the invocation result is returned from this function. If the option is none
, the callable is not invoked and none
is returned.
This function only participates in overload resolution if the invocation result of the callable is an option.
f | Callable applied to the contained option value |
|
inlineconstexprnoexcept |
Converts an option into an option of a reference.
This function acts as a monadic operation that gets a reference to the contained value without unwrapping the option. In the case where the contained value is void
, the returned option is also void
.
|
inlineconstexpr |
Constructs a new value in place into the option.
If the option already contains a value, the old value is first destroyed in place. In any case, a new value is constructed in place in the option.
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the error
value of the result. If the option is none
, the provided default value is used as the ok
value of the result.
err | The default ok value used if the option is none . |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the error
value of the result. If the option is none
, the provided default value is used as the ok
value of the result.
err | The default ok value used if the option is none . |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the error
value of the result. If the option is none
, the provided default value is used as the ok
value of the result.
err | The default ok value used if the option is none . |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the error
value of the result. If the option is none
, the provided default value is used as the ok
value of the result.
err | The default ok value used if the option is none . |
|
inlineconstexpr |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the error
value of the result. If the option is none
, the provided default value is used as the ok
value of the result.
The default ok value is always converted to a non-reference. If a reference is desired, use the overload of this function that accepts an ok_t.
This function only participates in overload resolution if U
is not an ok_t.
err | The default ok value used if the option is none . |
|
inlineconstexpr |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the error
value of the result. If the option is none
, the provided default value is used as the ok
value of the result.
The default ok value is always converted to a non-reference. If a reference is desired, use the overload of this function that accepts an ok_t.
This function only participates in overload resolution if U
is not an ok_t.
err | The default ok value used if the option is none . |
|
inlineconstexpr |
Converts an option to a result.
This fucntion constructs and returns a result such that the contained value of the option becomes the error
value of the result. If the option is none
, the result of invoking the provided callable is used as the ok
value of the result.
This function might be preferred over .error_or(ok_value)
when the value type is expensive to construct, copy, or move. This function allows the value to never be instantiated if the option is not none
.
f | A callable that creates a default ok value. |
|
inlineconstexpr |
Converts an option to a result.
This fucntion constructs and returns a result such that the contained value of the option becomes the error
value of the result. If the option is none
, the result of invoking the provided callable is used as the ok
value of the result.
This function might be preferred over .error_or(ok_value)
when the value type is expensive to construct, copy, or move. This function allows the value to never be instantiated if the option is not none
.
f | A callable that creates a default ok value. |
|
inlineconstexpr |
Filters the option based on a predicate.
If the option is already none
, none
is returned. If the option contains a value, the returned value depends on the predicate. If the predicate returns true
, an option with the moved original contained value is returned. Otherwise, none
is returned.
The predicate must have a signature compatible with: bool pred(T&)
or bool pred(const T&)
.
|
inlineconstexpr |
Filters the option based on a predicate.
If the option is already none
, none
is returned. If the option contains a value, the returned value depends on the predicate. If the predicate returns true
, an option with a copy of the original contained value is returned. Otherwise, none
is returned.
The predicate must have a signature compatible with: bool pred(const T&)
.
|
inlineconstexpr |
Converts option<option<T>>
to option<T>
If the outer option is none
or the inner option is none
, none
is returned. Otherwise the flattend option with a contained value is returned.
Note that only one level of option is removed. An option<option<option<T>>>
will flatten to an option<option<T>>
.
This function only participates in overload resolution if T
is an option.
|
inlineconstexpr |
Converts option<option<T>>
to option<T>
If the outer option is none
or the inner option is none
, none
is returned. Otherwise the flattend option with a contained value is returned.
Note that only one level of option is removed. An option<option<option<T>>>
will flatten to an option<option<T>>
.
This function only participates in overload resolution if T
is an option.
|
inlineconstexpr |
Converts nested option types into a single option.
Like flatten, this function removes nested layers of option, such as converting option<option<T>>
into option<T>
. However, unlike flatten, this function removes all layers of nesting and works for unnested option types. For example, option<option<option<T>>>
is converted directly to option<T>
, and for option<T>
, where T
is not an option type, no layers of option are removed.
|
inlineconstexpr |
Converts nested option types into a single option.
Like flatten, this function removes nested layers of option, such as converting option<option<T>>
into option<T>
. However, unlike flatten, this function removes all layers of nesting and works for unnested option types. For example, option<option<option<T>>>
is converted directly to option<T>
, and for option<T>
, where T
is not an option type, no layers of option are removed.
|
inlineconstexprnoexcept |
Returns true if the option contains a value.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Returns true if the option contains a value.
|
inlineconstexpr |
Performs a transformation on the content of an option.
This function is a monadic operation that passes the value contained in the option, if any, to the callable f
. The value returned by the call to f
is then returned from this function wrapped in a new option. If the original option is none
, the returned value is a none
option of the type that would have been returned by f
.
Note that this function is identical to transform, but the name map
is the more typical name of this monadic operation outside of C++.
f | A callable that maps the option value |
|
inlineconstexpr |
Performs a transformation on the content of an option.
This function is a monadic operation that passes the value contained in the option, if any, to the callable f
. The value returned by the call to f
is then returned from this function wrapped in a new option. If the original option is none
, the returned value is a none
option of the type that would have been returned by f
.
Note that this function is identical to transform, but the name map
is the more typical name of this monadic operation outside of C++.
f | A callable that maps the option value |
|
inlineconstexpr |
Performs a transformation on the content of an option.
This function is a monadic operation that passes the value contained in the option, if any, to the callable f
. The value returned by the call to f
is then returned from this function wrapped in a new option. If the original option is none
, the returned value is a none
option of the type that would have been returned by f
.
Note that this function is identical to transform, but the name map
is the more typical name of this monadic operation outside of C++.
f | A callable that maps the option value |
|
inlineconstexpr |
Performs a transformation on the content of an option.
This function is a monadic operation that passes the value contained in the option, if any, to the callable f
. The value returned by the call to f
is then returned from this function wrapped in a new option. If the original option is none
, the returned value is a none
option of the type that would have been returned by f
.
Note that this function is identical to transform, but the name map
is the more typical name of this monadic operation outside of C++.
f | A callable that maps the option value |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the ok
value of the result. If the option is none
, the provided error value is used as the error value of the result.
err | The default error value used if the option is none . |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the ok
value of the result. If the option is none
, the provided error value is used as the error value of the result.
err | The default error value used if the option is none . |
|
inlineconstexpr |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the ok
value of the result. If the option is none
, the provided default value is used as the error
value of the result.
The default error value is always converted to a non-reference. If a reference is desired, use the overload of this function that accepts an error_t.
This function only participates in overload resolution if E
is not an error_t.
err | The default error value used if the option is none . |
|
inlineconstexpr |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the ok
value of the result. If the option is none
, the provided default value is used as the error
value of the result.
The default error value is always converted to a non-reference. If a reference is desired, use the overload of this function that accepts an error_t.
This function only participates in overload resolution if E
is not an error_t.
err | The default error value used if the option is none . |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the ok
value of the result. If the option is none
, the provided error value is used as the error value of the result.
err | The default error value used if the option is none . |
Converts an option to a result.
This function constructs and returns a result such that the contained value of the option becomes the ok
value of the result. If the option is none
, the provided error value is used as the error value of the result.
err | The default error value used if the option is none . |
|
inlineconstexpr |
Converts an option to a result.
This fucntion constructs and returns a result such that the contained value of the option becomes the ok
value of the result. If the option is none
, the result of invoking the provided callable is used as the error value of the result.
This function might be preferred over .ok_or(error_value)
when the error type is expense to construct, copy, or move. This function allows the error value to never be instantiated if the option is not none
.
f | A callable that creates a default error value. |
|
inlineconstexpr |
Converts an option to a result.
This fucntion constructs and returns a result such that the contained value of the option becomes the ok
value of the result. If the option is none
, the result of invoking the provided callable is used as the error value of the result.
This function might be preferred over .ok_or(error_value)
when the error type is expense to construct, copy, or move. This function allows the error value to never be instantiated if the option is not none
.
f | A callable that creates a default error value. |
|
inlineconstexprnoexcept |
Implicit conversion to bool
.
This implicit conversion allows an option to be used directly in a condition to check if the option contains a value.
|
inlineconstexprnoexcept |
Conversion to raw pointer.
This conversion allows an option of an lvalue to be converted into a raw pointer, where the resulting pointer points to the referenced value or is null if the option is none.
This conversion only participates in overload resolution if T
is an lvalue reference and pointer
can be cast to U*
.
This conversion is explicit if pointer
is not implicitly convertible to U*
.
|
inlineconstexpr |
|
inlineconstexprnoexcept |
|
inlineconstexpr |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Copy assignment operator.
The destination option is reassigned such that it contains the value of the source option, if it has any.
If both the source and desitnation option are not none
, then the value contained in the destination option is copy assigned from the value contained in the source option.
If the source option contains a value and the destination is none
, the value contained in the source option is destroyed in place, making the destination option none
.
If the source option is none
and the destination contains a value, a new value is copy constructed in place in the source option.
If both the source and destination option are none
, both remain none
.
This function is noexcept
if the contained value type is nothrow copy assignable, nothrow copy constructible, and nothrow destructible.
Converting copy assignment operator.
This function performs copy assignment just like the standard copy assignment operator, but it also performs conversion from the value contained in the source option to the value type of contained in the destination option.
This function only participates in overload resolution if T
is not construcitble from, convertible from, or assignable from any cvref qualified form of option<U>
, and T
is both constructible and assignable from U
.
Move assignment operator.
The destination option is reassigned such that it contains the moved value of the source option, if it has any. In all cases, the source option will be none
after the move.
If both the source and destination option are not none
, then the value contained in the destination option is move assigned from the moved value from the source option. The old value in the source option is destroyed in place.
If the source option contains a value and the desitnation is none
, the value contained in the source option is destroyed in place, making the desitnation option none
.
If the source option is none
and the destination contains a value, a new value is move constructed in place in the source option. The old value in the source option is destroyed in place.
If both the source and destination option are none
, both remain none
.
This function is noexcept
if the contained value type is nothrow move assignable, nothrow move constructible, and nothrow destructible.
Converting move assignment operator.
This function performs move assignment just like the standard move assignment operator, but it also performs conversion from the value contained in the source option to the value type of contained in the destination option.
This function only participates in overload resolution if T
is not construcitble from, convertible from, or assignable from any cvref qualified form of option<U>
, and T
is both constructible and assignable from U
.
Value assignment operator.
Sets the option to contain the provided value, converted to T
. If the option holds a value (is not none
) before the assigment, the value is directly assigned the forwarded source value. If the option is none
, a new value is constructed in place from the forwarded source value.
This function only participates in overload resolution if:
T
is constructible from U
T
is assignable from U
T
is not scalar or U
is not equivalent to T
Pointer assignment operator.
The destination option is assigned such that it contains an lvalue reference that the source pointer points to. If the pointer is null, the destination option will be none
.
This function only participates in overload resolution if T
is an lvalue reference and the pointer U*
can be implicitly converted to pointer
.
|
inlineconstexpr |
Returns the result of f
if the option is none
.
If the option contains a value, a copy of the option is returned. Otherwise, the result of invoking f
is returned.
f | A callable that returns the "else" option |
|
inlineconstexpr |
Returns the result of f
if the option is none
.
If the option contains a value, a copy of the option is returned. Otherwise, the result of invoking f
is returned.
f | A callable that returns the "else" option |
|
inlineconstexprnoexcept |
Converts an option into an option of a reference.
This function acts as a monadic operation that gets a reference to the contained value without unwrapping the option. In the case where the contained value is void
, the returned option is also void
.
|
inlineconstexprnoexcept |
Converts an option into an option of a reference.
This function acts as a monadic operation that gets a reference to the contained value without unwrapping the option. In the case where the contained value is void
, the returned option is also void
.
|
inlineconstexprnoexcept |
|
inlineconstexpr |
Accesses the value contained in the option.
This function first checks if the option contains a value before attempting to access the value. If the option is none
, then this function throws an exception.
bad_option_access | Thrown if the option is none . |
|
inlineconstexpr |
Accesses the value contained in the option.
This function first checks if the option contains a value before attempting to access the value. If the option is none
, then this function throws an exception.
bad_option_access | Thrown if the option is none . |
|
inlineconstexpr |
Accesses the value contained in the option.
This function first checks if the option contains a value before attempting to access the value. If the option is none
, then this function throws an exception.
bad_option_access | Thrown if the option is none . |
|
inlineconstexpr |
Accesses the value contained in the option.
This function first checks if the option contains a value before attempting to access the value. If the option is none
, then this function throws an exception.
bad_option_access | Thrown if the option is none . |
|
inlineconstexpr |
Gets the option value with a default used for none
.
If the option contains a value, the moved value is returned. If the option is none
, the provided default value is returned as static_cast<T>(std::forward<U>(default_value))
.
default_value | The value to use if the option is none . |
|
inlineconstexpr |
Gets the option value with a default used for none
.
If the option contains a value, a copy of the value is returned. If the option is none
, the provided default value is returned as static_cast<T>(std::forward<U>(default_value))
.
default_value | The value to use if the option is none . |
|
inlineconstexpr |
Gets the option value with a default used for none
.
If the option contains a value, the moved value is returned. If the option is none
, the result of invoking f
is returned. The returned value of f
is also explicitly cast to value_type
before return.
This function might be preferred over .value_or(default_value)
when the default value is expensive to create or move. This function allows the default value to never be instantiated if the option is not none
.
f | A callable that creates a default value. |
|
inlineconstexpr |
Gets the option value with a default used for none
.
If the option contains a value, the copied value is returned. If the option is none
, the result of invoking f
is returned. The returned value of f
is also explicitly cast to value_type
before return.
This function might be preferred over .value_or(default_value)
when the default value is expensive to create or move. This function allows the default value to never be instantiated if the option is not none
.
f | A callable that creates a default value. |
|
inlineconstexpr |
Swaps two option instances.
If both option instances contain a value, the two contained values are swapped directly. Otherwise, if one option contains a value, that value is move constructed into the other option, and the old value is destroyed in place. If both option instances are none
, nothing is done.
This function is noexcept
if the contained value type is nothrow swappable.
|
inlineconstexpr |
Performs a transformation on the content of an option.
This function is a monadic operation that passes the value contained in the option, if any, to the callable f
. The value returned by the call to f
is then returned from this function wrapped in a new option. If the original option is none
, the returned value is a none
option of the type that would have been returned by f
.
Note that this function is identical to map, but the name transform
make option able to be a drop in replacement for std::optional
. map
is the more typical name of this monadic operation outside of C++.
f | A callable that transforms the option value |
|
inlineconstexpr |
Performs a transformation on the content of an option.
This function is a monadic operation that passes the value contained in the option, if any, to the callable f
. The value returned by the call to f
is then returned from this function wrapped in a new option. If the original option is none
, the returned value is a none
option of the type that would have been returned by f
.
Note that this function is identical to map, but the name transform
make option able to be a drop in replacement for std::optional
. map
is the more typical name of this monadic operation outside of C++.
f | A callable that transforms the option value |
|
inlineconstexpr |
Performs a transformation on the content of an option.
This function is a monadic operation that passes the value contained in the option, if any, to the callable f
. The value returned by the call to f
is then returned from this function wrapped in a new option. If the original option is none
, the returned value is a none
option of the type that would have been returned by f
.
Note that this function is identical to map, but the name transform
make option able to be a drop in replacement for std::optional
. map
is the more typical name of this monadic operation outside of C++.
f | A callable that transforms the option value |
|
inlineconstexpr |
Performs a transformation on the content of an option.
This function is a monadic operation that passes the value contained in the option, if any, to the callable f
. The value returned by the call to f
is then returned from this function wrapped in a new option. If the original option is none
, the returned value is a none
option of the type that would have been returned by f
.
Note that this function is identical to map, but the name transform
make option able to be a drop in replacement for std::optional
. map
is the more typical name of this monadic operation outside of C++.
f | A callable that transforms the option value |
|
inlineconstexpr |
Converts option<result<T, E>>
into result<option<T>, E>
If the option is none
, a result containing a none
option is returned. If the option contains an ok result, a result containing an ok value of an option with a value is returned. If the option contains a result with an error value, a result with an error value is returned.
This function only participates in overload resolution if T
is a result.
|
inlineconstexpr |
Converts option<result<T, E>>
into result<option<T>, E>
If the option is none
, a result containing a none
option is returned. If the option contains an ok result, a result containing an ok value of an option with a value is returned. If the option contains a result with an error value, a result with an error value is returned.
This function only participates in overload resolution if T
is a result.
|
inlineconstexpr |
Accesses the value contained in the option.
This function first checks if the option contains a value before attempting to access the value. If the option is none
, then this function throws an exception.
bad_option_access | Thrown if the option is none . |
|
inlineconstexpr |
Accesses the value contained in the option.
This function first checks if the option contains a value before attempting to access the value. If the option is none
, then this function throws an exception.
bad_option_access | Thrown if the option is none . |
|
inlineconstexpr |
Accesses the value contained in the option.
This function first checks if the option contains a value before attempting to access the value. If the option is none
, then this function throws an exception.
bad_option_access | Thrown if the option is none . |
|
inlineconstexpr |
Accesses the value contained in the option.
This function first checks if the option contains a value before attempting to access the value. If the option is none
, then this function throws an exception.
bad_option_access | Thrown if the option is none . |
|
inlineconstexpr |
Gets the option value with a default used for none
.
If the option contains a value, the moved value is returned. If the option is none
, the provided default value is returned as static_cast<T>(std::forward<U>(default_value))
.
default_value | The value to use if the option is none . |
|
inlineconstexpr |
Gets the option value with a default used for none
.
If the option contains a value, a copy of the value is returned. If the option is none
, the provided default value is returned as static_cast<T>(std::forward<U>(default_value))
.
default_value | The value to use if the option is none . |
|
inlineconstexpr |
Gets the option value with a default used for none
.
If the option contains a value, the moved value is returned. If the option is none
, the result of invoking f
is returned. The returned value of f
is also explicitly cast to value_type
before return.
This function might be preferred over .value_or(default_value)
when the default value is expensive to create or move. This function allows the default value to never be instantiated if the option is not none
.
f | A callable that creates a default value. |
|
inlineconstexpr |
Gets the option value with a default used for none
.
If the option contains a value, the copied value is returned. If the option is none
, the result of invoking f
is returned. The returned value of f
is also explicitly cast to value_type
before return.
This function might be preferred over .value_or(default_value)
when the default value is expensive to create or move. This function allows the default value to never be instantiated if the option is not none
.
f | A callable that creates a default value. |
|
inlineconstexpr |
Calls a visitor callable with the contained value or void
.
This function treats an option as if it was a variant of void
and T
. If the option contains a value, that value is passed to the visitor. If the option is none
, the visitor is called with void_t.
Note that the overload function can be helpful for defining a visitor inline.
|
inlineconstexpr |
Calls a visitor callable with the contained value or void
.
This function treats an option as if it was a variant of void
and T
. If the option contains a value, that value is passed to the visitor. If the option is none
, the visitor is called without any arguments.
Note that the overload function can be helpful for defining a visitor inline.
|
inlineconstexpr |
Calls a visitor callable with the contained value or void
.
This function treats an option as if it was a variant of void
and T
. If the option contains a value, that value is passed to the visitor. If the option is none
, the visitor is called with void_t.
Note that the overload function can be helpful for defining a visitor inline.
|
inlineconstexpr |
Calls a visitor callable with the contained value or void
.
This function treats an option as if it was a variant of void
and T
. If the option contains a value, that value is passed to the visitor. If the option is none
, the visitor is called with void_t.
Note that the overload function can be helpful for defining a visitor inline.
|
inlineconstexpr |
Calls a visitor callable with the contained value and meta data.
This function treats an option as if it was a variant of void
and T
. If the option contains a value, that value is passed to the visitor. If the option is none
, the visitor is called with void_t.
In either case, an additional (second) parameter is passed to the visitor, which provides constexpr
information about the specific alternative being visited. This info
parameter has the API shown below. Note that this type is always an empty type.
Note that the overload function can be helpful for defining a visitor inline.
|
inlineconstexpr |
Calls a visitor callable with the contained value and meta data.
This function treats an option as if it was a variant of void
and T
. If the option contains a value, that value is passed to the visitor. If the option is none
, the visitor is called with void_t.
In either case, an additional (second) parameter is passed to the visitor, which provides constexpr
information about the specific alternative being visited. This info
parameter has the API shown below. Note that this type is always an empty type.
Note that the overload function can be helpful for defining a visitor inline.
|
inlineconstexpr |
Calls a visitor callable with the contained value and meta data.
This function treats an option as if it was a variant of void
and T
. If the option contains a value, that value is passed to the visitor. If the option is none
, the visitor is called with void_t.
In either case, an additional (second) parameter is passed to the visitor, which provides constexpr
information about the specific alternative being visited. This info
parameter has the API shown below. Note that this type is always an empty type.
Note that the overload function can be helpful for defining a visitor inline.
|
inlineconstexpr |
Calls a visitor callable with the contained value and meta data.
This function treats an option as if it was a variant of void
and T
. If the option contains a value, that value is passed to the visitor. If the option is none
, the visitor is called with void_t.
In either case, an additional (second) parameter is passed to the visitor, which provides constexpr
information about the specific alternative being visited. This info
parameter has the API shown below. Note that this type is always an empty type.
Note that the overload function can be helpful for defining a visitor inline.
|
related |
Gets an option value by index, as if it were a variant.
This function is provided to make option generically compatible with variant. This function treats option<T>
as if it were variant<void, T>
, where index 0 gets void
(which represents none
) and index 1 gets T
(which is the contained value).
IDX | The "alternative" index |
opt | The option to access |
bad_option_access | Thrown if the option state does not match the index IDX . |
|
related |
Gets an option value by index, as if it were a variant.
This function is provided to make option generically compatible with variant. This function treats option<T>
as if it were variant<void, T>
, where index 0 gets void
(which represents none
) and index 1 gets T
(which is the contained value).
IDX | The "alternative" index |
opt | The option to access |
bad_option_access | Thrown if the option state does not match the index IDX . |
|
related |
Gets an option value by type, as if it were a variant.
This function is provided to make option generically compatible with variant. This function treats option<T>
as if it were variant<void, T>
, where void
is the none
alternative, and T
is the alternative with a value.
This function only participates in overload resolution if the contained value of the option is not void
.
T | The type of the alternative to access |
opt | The option to access |
bad_option_access | Thrown if the option does not contain the requested type T . |
|
related |
Gets an option value by type, as if it were a variant.
This function is provided to make option generically compatible with variant. This function treats option<T>
as if it were variant<void, T>
, where void
is the none
alternative, and T
is the alternative with a value.
This function only participates in overload resolution if the contained value of the option is not void
.
T | The type of the alternative to access |
opt | The option to access |
bad_option_access | Thrown if the option does not contain the requested type T . |
|
related |
Gets an option value by index, as if it were a variant.
This function is provided to make option generically compatible with variant. This function treats option<T>
as if it were variant<void, T>
, where index 0 gets void
(which represents none
) and index 1 gets T
(which is the contained value).
IDX | The "alternative" index |
opt | The option to access |
bad_option_access | Thrown if the option state does not match the index IDX . |
|
related |
Gets an option value by index, as if it were a variant.
This function is provided to make option generically compatible with variant. This function treats option<T>
as if it were variant<void, T>
, where index 0 gets void
(which represents none
) and index 1 gets T
(which is the contained value).
IDX | The "alternative" index |
opt | The option to access |
bad_option_access | Thrown if the option state does not match the index IDX . |
|
related |
Gets an option value by type, as if it were a variant.
This function is provided to make option generically compatible with variant. This function treats option<T>
as if it were variant<void, T>
, where void
is the none
alternative, and T
is the alternative with a value.
This function only participates in overload resolution if the contained value of the option is not void
.
T | The type of the alternative to access |
opt | The option to access |
bad_option_access | Thrown if the option does not contain the requested type T . |
|
related |
Gets an option value by type, as if it were a variant.
This function is provided to make option generically compatible with variant. This function treats option<T>
as if it were variant<void, T>
, where void
is the none
alternative, and T
is the alternative with a value.
This function only participates in overload resolution if the contained value of the option is not void
.
T | The type of the alternative to access |
opt | The option to access |
bad_option_access | Thrown if the option does not contain the requested type T . |
Compares two option instances.
none
is always less than any contained value.
|
related |
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
|
related |
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
|
related |
Compares an option with none
.
none
is always less than an option with a contained value.
|
related |
Compares an option with std::nullopt
.
std::nullopt
is always less than an option with a contained value.
|
related |
|
related |
|
related |
Tests two option instances for inequality.
|
related |
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
|
related |
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
|
related |
|
related |
|
related |
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
|
related |
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
|
related |
Compares two option instances.
none
is always less than any contained value.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
|
related |
Compares two option instances.
none
is always less than any contained value.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
Tests two option instances for equality.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
|
related |
Compares two option instances.
none
is always less than any contained value.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
|
related |
Compares two option instances.
none
is always less than any contained value.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
Compares an option with a value.
none
is always less than the value. If not none
, the contained value is compared with the value.
Compares an option with a pointer.
An option of an lvalue reference is a smart pointer and is directly comparable with raw pointers, where none
is null, and a contained value is a non-null address.
This function only participates in overload resolution if the contained type of the option is an lvalue reference.
|
related |
Constructs an option that contains a value.
This function is the counterpart to none that creates an option that contains a value instead of being none
. The contained value is constructed in place in the option, which is then RVO returned.
A call to this function must explicitly specify the type T
that the option should contain, and the passed arguments are forwarded to the constructor of that type.
|
related |
Constructs an option that contains a value.
This function is the counterpart to none that creates an option that contains a value instead of being none
. The contained value is constructed in place in the option, which is then RVO returned.
A call to this function must explicitly specify the type T
that the option should contain, and the passed arguments are forwarded to the constructor of that type.
Swaps two option instances.
If both option instances contain a value, the two contained values are swapped directly. Otherwise, if one option contains a value, that value is move constructed into the other option, and the old value is destroyed in place. If both option instances are none
, nothing is done.
This function is noexcept
if the contained value type is nothrow swappable.