enum_name
Loading...
Searching...
No Matches
Public Member Functions | List of all members
mgutility::optional< T > Class Template Reference

A class template that provides optional (nullable) objects. More...

#include <optional.hpp>

Public Member Functions

MGUTILITY_CNSTXPR optional (nullopt_t &)
 Constructs an empty optional.
 
MGUTILITY_CNSTXPR optional ()
 Constructs an empty optional.
 
template<typename... Args>
MGUTILITY_CNSTXPR optional (Args &&...args)
 Constructs an optional with a value.
 
MGUTILITY_CNSTXPR optional (T &&value)
 Constructs an optional with a value.
 
MGUTILITY_CNSTXPR optional (const optional &other)
 Copy constructor.
 
MGUTILITY_CNSTXPR optional (optional &&other)
 Move constructor.
 
 ~optional ()
 Destructor.
 
MGUTILITY_CNSTXPR optionaloperator= (const optional &other)
 Copy assignment operator.
 
MGUTILITY_CNSTXPR optionaloperator= (optional &&other)
 Move assignment operator.
 
MGUTILITY_CNSTXPR void swap (optional &&other)
 Swaps the contents of this optional with another.
 
MGUTILITY_CNSTXPR T & operator* ()
 Dereferences the stored value.
 
MGUTILITY_CNSTXPR T & operator* () const
 Dereferences the stored value (const version).
 
MGUTILITY_CNSTXPR T & value ()
 Accesses the stored value.
 
MGUTILITY_CNSTXPR T & value () const
 Accesses the stored value (const version).
 
MGUTILITY_CNSTXPR T value_or (T &&value)
 Returns the stored value or a default value if empty.
 
MGUTILITY_CNSTXPR T value_or (T &&value) const
 Returns the stored value or a default value if empty (const version).
 
MGUTILITY_CNSTXPR T value_or (const T &value)
 Returns the stored value or a default value if empty.
 
MGUTILITY_CNSTXPR T value_or (const T &value) const
 Returns the stored value or a default value if empty (const version).
 
MGUTILITY_CNSTXPR void emplace (T value)
 Constructs the value in-place.
 
template<typename... Args>
MGUTILITY_CNSTXPR void emplace (Args &&...args)
 Constructs the value in-place with arguments.
 
MGUTILITY_CNSTXPR bool has_value () const
 Checks if the optional has a value.
 
template<typename U = T, detail::enable_if_t<!std::is_destructible< U >::value, bool > = true>
MGUTILITY_CNSTXPR void reset ()
 Resets the optional, making it empty.
 
template<typename U = T, detail::enable_if_t< std::is_destructible< T >::value, bool > = true>
MGUTILITY_CNSTXPR void reset ()
 Resets the optional, making it empty.
 
MGUTILITY_CNSTXPR operator bool ()
 Checks if the optional has a value.
 

Detailed Description

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

A class template that provides optional (nullable) objects.

Template Parameters
TThe type of the value.

Constructor & Destructor Documentation

◆ optional() [1/4]

template<typename T >
template<typename... Args>
MGUTILITY_CNSTXPR mgutility::optional< T >::optional ( Args &&... args)
inline

Constructs an optional with a value.

Template Parameters
ArgsThe types of the arguments.
Parameters
argsThe arguments to construct the value.

◆ optional() [2/4]

template<typename T >
MGUTILITY_CNSTXPR mgutility::optional< T >::optional ( T && value)
inline

Constructs an optional with a value.

Parameters
valueThe value to initialize with.

◆ optional() [3/4]

template<typename T >
MGUTILITY_CNSTXPR mgutility::optional< T >::optional ( const optional< T > & other)
inline

Copy constructor.

Parameters
otherThe other optional to copy.

◆ optional() [4/4]

template<typename T >
MGUTILITY_CNSTXPR mgutility::optional< T >::optional ( optional< T > && other)
inline

Move constructor.

Parameters
otherThe other optional to move.

Member Function Documentation

◆ emplace() [1/2]

template<typename T >
template<typename... Args>
MGUTILITY_CNSTXPR void mgutility::optional< T >::emplace ( Args &&... args)
inline

Constructs the value in-place with arguments.

Template Parameters
ArgsThe types of the arguments.
Parameters
argsThe arguments to construct the value.

◆ emplace() [2/2]

template<typename T >
MGUTILITY_CNSTXPR void mgutility::optional< T >::emplace ( T value)
inline

Constructs the value in-place.

Parameters
valueThe value to emplace.

◆ has_value()

template<typename T >
MGUTILITY_CNSTXPR bool mgutility::optional< T >::has_value ( ) const
inline

Checks if the optional has a value.

Returns
True if the optional has a value, otherwise false.

◆ operator bool()

template<typename T >
MGUTILITY_CNSTXPR mgutility::optional< T >::operator bool ( )
inline

Checks if the optional has a value.

Returns
True if the optional has a value, otherwise false.

◆ operator*() [1/2]

template<typename T >
MGUTILITY_CNSTXPR T & mgutility::optional< T >::operator* ( )
inline

Dereferences the stored value.

Returns
A reference to the stored value.

◆ operator*() [2/2]

template<typename T >
MGUTILITY_CNSTXPR T & mgutility::optional< T >::operator* ( ) const
inline

Dereferences the stored value (const version).

Returns
A reference to the stored value.

◆ operator=() [1/2]

template<typename T >
MGUTILITY_CNSTXPR optional & mgutility::optional< T >::operator= ( const optional< T > & other)
inline

Copy assignment operator.

Parameters
otherThe other optional to copy.
Returns
A reference to this optional.

◆ operator=() [2/2]

template<typename T >
MGUTILITY_CNSTXPR optional & mgutility::optional< T >::operator= ( optional< T > && other)
inline

Move assignment operator.

Parameters
otherThe other optional to move.
Returns
A reference to this optional.

◆ swap()

template<typename T >
MGUTILITY_CNSTXPR void mgutility::optional< T >::swap ( optional< T > && other)
inline

Swaps the contents of this optional with another.

Parameters
otherThe other optional to swap with.

◆ value() [1/2]

template<typename T >
MGUTILITY_CNSTXPR T & mgutility::optional< T >::value ( )
inline

Accesses the stored value.

Returns
A reference to the stored value.
Exceptions
bad_optional_accessif the optional has no value.

◆ value() [2/2]

template<typename T >
MGUTILITY_CNSTXPR T & mgutility::optional< T >::value ( ) const
inline

Accesses the stored value (const version).

Returns
A reference to the stored value.
Exceptions
bad_optional_accessif the optional has no value.

◆ value_or() [1/4]

template<typename T >
MGUTILITY_CNSTXPR T mgutility::optional< T >::value_or ( const T & value)
inline

Returns the stored value or a default value if empty.

Parameters
valueThe default value to return if empty.
Returns
The stored value or the default value.

◆ value_or() [2/4]

template<typename T >
MGUTILITY_CNSTXPR T mgutility::optional< T >::value_or ( const T & value) const
inline

Returns the stored value or a default value if empty (const version).

Parameters
valueThe default value to return if empty.
Returns
The stored value or the default value.

◆ value_or() [3/4]

template<typename T >
MGUTILITY_CNSTXPR T mgutility::optional< T >::value_or ( T && value)
inline

Returns the stored value or a default value if empty.

Parameters
valueThe default value to return if empty.
Returns
The stored value or the default value.

◆ value_or() [4/4]

template<typename T >
MGUTILITY_CNSTXPR T mgutility::optional< T >::value_or ( T && value) const
inline

Returns the stored value or a default value if empty (const version).

Parameters
valueThe default value to return if empty.
Returns
The stored value or the default value.

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