ipaddress 1.1.0
Loading...
Searching...
No Matches
optional< T > Class Template Reference

A template class to manage an optional contained value. More...

#include <optional.hpp>

Public Types

using value_type = T
 The type of the value to manage initialization state for.
 

Public Member Functions

constexpr inline optional () noexcept(noexcept(T()))=default
 Default constructor that constructs an optional object without a contained value.
 
constexpr inline optional (std::nullptr_t) noexcept(noexcept(T()))
 Constructs an optional object that does not contain a value.
 
constexpr inline optional (const value_type &val) noexcept(noexcept(T(val)))
 Copy constructor that constructs an optional object with a contained value, initializing it with val.
 
constexpr inline optional (value_type &&val) noexcept
 Move constructor that constructs an optional object with a contained value, initializing it with val.
 
constexpr inline optional (const optional< T > &opt) noexcept
 Copy constructor that constructs an optional object with a contained value, copying it from opt.
 
constexpr inline optionaloperator= (std::nullptr_t) noexcept
 Assignment operator that clears the contained value of the optional object.
 
constexpr inline optionaloperator= (value_type &&val) noexcept
 Move assignment operator that sets the contained value of the optional object to val.
 
constexpr inline optionaloperator= (const optional< T > &opt) noexcept
 Assigns the value and the state of existence from another optional object.
 
constexpr inline value_typeoperator-> () noexcept
 Pointer access to the contained value.
 
constexpr inline const value_typeoperator-> () const noexcept
 Constant pointer access to the contained value.
 
constexpr inline value_typeoperator* () noexcept
 Reference access to the contained value.
 
constexpr inline const value_typeoperator* () const noexcept
 Constant reference access to the contained value.
 
constexpr inline operator bool () const noexcept
 Checks existence of the contained value.
 
constexpr inline bool has_value () const noexcept
 Checks existence of the contained value.
 
constexpr inline value_typevalue () &noexcept
 Reference access to the contained value.
 
constexpr inline const value_typevalue () const &noexcept
 Constant reference access to the contained value.
 
constexpr inline value_type && value () &&noexcept
 Move access to the contained value.
 
constexpr inline const value_type && value () const &&noexcept
 Constant move access to the contained value.
 

Detailed Description

template<typename T>
class ipaddress::optional< T >

A template class to manage an optional contained value.

The optional class template is often used to represent the outcome of a function that might not succeed. An optional<T> can either hold a value or be empty at any moment. When it does hold a value, that value is stored within the optional object itself, meaning there’s no need for separate dynamic memory allocation. If you check an optional<T> in a boolean context, such as in an if-statement, it will evaluate to true if there’s a value present, and false otherwise.

Template Parameters
TThe type of the value to manage initialization state for.

Constructor & Destructor Documentation

◆ optional() [1/3]

template<typename T >
constexpr inline optional ( const value_type & val)
inlinenoexcept

Copy constructor that constructs an optional object with a contained value, initializing it with val.

Parameters
[in]valThe value to copy into the optional object.

◆ optional() [2/3]

template<typename T >
constexpr inline optional ( value_type && val)
inlinenoexcept

Move constructor that constructs an optional object with a contained value, initializing it with val.

Parameters
[in,out]valThe value to move into the optional object.

◆ optional() [3/3]

template<typename T >
constexpr inline optional ( const optional< T > & opt)
inlinenoexcept

Copy constructor that constructs an optional object with a contained value, copying it from opt.

Parameters
[in]optThe optional object to copy the value from.

Member Function Documentation

◆ operator=() [1/3]

template<typename T >
constexpr inline optional & operator= ( std::nullptr_t )
inlinenoexcept

Assignment operator that clears the contained value of the optional object.

Returns
A reference to the optional object.

◆ operator=() [2/3]

template<typename T >
constexpr inline optional & operator= ( value_type && val)
inlinenoexcept

Move assignment operator that sets the contained value of the optional object to val.

Parameters
[in,out]valThe value to move into the optional object.
Returns
A reference to the optional object.

◆ operator=() [3/3]

template<typename T >
constexpr inline optional & operator= ( const optional< T > & opt)
inlinenoexcept

Assigns the value and the state of existence from another optional object.

Parameters
[in]optThe optional object to copy from.
Returns
A reference to *this.

◆ operator->() [1/2]

template<typename T >
constexpr inline value_type * operator-> ( )
inlinenoexcept

Pointer access to the contained value.

Provides pointer access to the contained value. It is undefined behavior if the optional object does not contain a value.

Returns
A pointer to the contained value.

◆ operator->() [2/2]

template<typename T >
constexpr inline const value_type * operator-> ( ) const
inlinenoexcept

Constant pointer access to the contained value.

Provides constant pointer access to the contained value. It is undefined behavior if the optional object does not contain a value.

Returns
A constant pointer to the contained value.

◆ operator*() [1/2]

template<typename T >
constexpr inline value_type & operator* ( )
inlinenoexcept

Reference access to the contained value.

Provides reference access to the contained value. It is undefined behavior if the optional object does not contain a value.

Returns
A reference to the contained value.

◆ operator*() [2/2]

template<typename T >
constexpr inline const value_type & operator* ( ) const
inlinenoexcept

Constant reference access to the contained value.

Provides constant reference access to the contained value. It is undefined behavior if the optional object does not contain a value.

Returns
A constant reference to the contained value.

◆ operator bool()

template<typename T >
constexpr inline operator bool ( ) const
inlineexplicitnoexcept

Checks existence of the contained value.

Determines whether the optional object contains a value.

Returns
true if a value is contained, otherwise false.

◆ has_value()

template<typename T >
constexpr inline bool has_value ( ) const
inlinenoexcept

Checks existence of the contained value.

Determines whether the optional object contains a value.

Returns
true if a value is contained, otherwise false.

◆ value() [1/4]

template<typename T >
constexpr inline value_type & value ( ) &
inlinenoexcept

Reference access to the contained value.

Provides reference access to the contained value. It is undefined behavior if the optional object does not contain a value.

Returns
A reference to the contained value.

◆ value() [2/4]

template<typename T >
constexpr inline const value_type & value ( ) const &
inlinenoexcept

Constant reference access to the contained value.

Provides constant reference access to the contained value. It is undefined behavior if the optional object does not contain a value.

Returns
A constant reference to the contained value.

◆ value() [3/4]

template<typename T >
constexpr inline value_type && value ( ) &&
inlinenoexcept

Move access to the contained value.

Moves the contained value. It is undefined behavior if the optional object does not contain a value.

Returns
The contained value, moved.

◆ value() [4/4]

template<typename T >
constexpr inline const value_type && value ( ) const &&
inlinenoexcept

Constant move access to the contained value.

Moves the contained value, maintaining constness. It is undefined behavior if the optional object does not contain a value.

Returns
The contained value, moved, as a constant.

The documentation for this class was generated from the following file: