matador::optional< T > Class Template Reference

#include <optional.hpp>

Public Types

typedef T value_type
 

Public Member Functions

 optional ()=default
 
 optional (detail::nullopt_t)
 
 optional (const T &value)
 
template<class U >
 optional (const optional< U > &x)
 
optionaloperator= (detail::nullopt_t)
 
template<class U >
optionaloperator= (const optional< U > &x)
 
const value_typeoperator-> () const
 
value_typeoperator-> ()
 
const value_typeoperator* () const
 
value_typeoperator* ()
 
 operator bool () const
 
const value_typevalue () const
 
value_typevalue ()
 
template<class U >
value_type value_or (U const &v) const
 
bool has_value () const
 
void reset ()
 

Detailed Description

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

The optional class provides an object holding a value of type T or not. The value is optional.

Template Parameters
TType of the hold optional value

Member Typedef Documentation

◆ value_type

template<typename T >
typedef T matador::optional< T >::value_type

Shortcut to the value type

Constructor & Destructor Documentation

◆ optional() [1/4]

template<typename T >
matador::optional< T >::optional ( )
default

Default constructor

◆ optional() [2/4]

template<typename T >
matador::optional< T >::optional ( detail::nullopt_t  )
inline

Initializes the optional with a null type.

◆ optional() [3/4]

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

Initializes a new optional with the given value.

Parameters
valueValue of optional

◆ optional() [4/4]

template<typename T >
template<class U >
matador::optional< T >::optional ( const optional< U > &  x)
inline

Copies given optional value x of type U to new optional value of type T. A value of type U must be convertible to type T.

Template Parameters
UType of other optional
Parameters
xOther optional value

Member Function Documentation

◆ has_value()

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

Returns true if value is set.

Returns
True if value is set

◆ operator bool()

template<typename T >
matador::optional< T >::operator bool ( ) const
inlineexplicit

Boolean operator returns true if optional has a value

Returns
True if valueis available

◆ operator*() [1/2]

template<typename T >
value_type & matador::optional< T >::operator* ( )
inline

Access the underlying value as reference. The value is checked on validity with assert

Returns
The value as reference

◆ operator*() [2/2]

template<typename T >
const value_type & matador::optional< T >::operator* ( ) const
inline

Access the underlying value as reference. The value is checked on validity with assert

Returns
The value as reference

◆ operator->() [1/2]

template<typename T >
value_type * matador::optional< T >::operator-> ( )
inline

Access the underlying value as pointer. The value is checked on validity with assert

Returns
The value as pointer

◆ operator->() [2/2]

template<typename T >
const value_type * matador::optional< T >::operator-> ( ) const
inline

Access the underlying value as pointer. The value is checked on validity with assert

Returns
The value as pointer

◆ operator=() [1/2]

template<typename T >
template<class U >
optional & matador::optional< T >::operator= ( const optional< U > &  x)
inline

Assigns an other optional of type U to this optional. Type U must be convertible to type T.

Template Parameters
UType of other optional
Parameters
xOther optional to be assigned
Returns
The assigned optional

◆ operator=() [2/2]

template<typename T >
optional & matador::optional< T >::operator= ( detail::nullopt_t  )
inline

Assigns a null optional value to this optional. Optional will be set to nullopt.

Returns
The assigned optional

◆ reset()

template<typename T >
void matador::optional< T >::reset ( )
inline

Resets optional to empty (no value set)

◆ value() [1/2]

template<typename T >
value_type & matador::optional< T >::value ( )
inline

Returns a reference to the value. If value isn't available a bad_optional_exception is thrown

Exceptions
bad_optional_exceptionIf not available
Returns
Reference to the value

◆ value() [2/2]

template<typename T >
const value_type & matador::optional< T >::value ( ) const
inline

Returns a const reference to the value. If value isn't available a bad_optional_exception is thrown

Exceptions
bad_optional_exceptionIf not available
Returns
Const reference to the value

◆ value_or()

template<typename T >
template<class U >
value_type matador::optional< T >::value_or ( U const &  v) const
inline

Return a copy of the value or in case value is not set return the given value

This default value is of type U and must be convertible to type T.

Template Parameters
UType of default value
Parameters
vDefault value if optional value is not set
Returns
Optional value or default value

The documentation for this class was generated from the following file:
  • matador/utils/optional.hpp