3.0.0
Freundlich's C++ toolkit
Public Types | Public Member Functions
fcppt::optional::object< T > Class Template Reference

Detailed Description

template<typename T>
class fcppt::optional::object< T >

A class that makes values optional.

This class is a wrapper around std::optional that makes the following changes:

Template Parameters
TThe type to make optional, which must be CopyConstructible or Movable, Assignable or MoveAssignable and complete. It therefore must also not be const.

See the module description for more information.

Public Types

typedef T value_type
 The value type. More...
 

Public Member Functions

 object ()
 Constructs an empty optional. More...
 
 object (T const &)
 Constructs an optional by copying. More...
 
 object (T &&)
 Constructs an optional by moving. More...
 
T & get_unsafe ()
 Returns a reference to the current value. More...
 
T const & get_unsafe () const
 Returns a const reference to the current value. More...
 
bool has_value () const
 Returns whether the optional holds a value. More...
 

Member Typedef Documentation

◆ value_type

template<typename T>
typedef T fcppt::optional::object< T >::value_type

The value type.

Constructor & Destructor Documentation

◆ object() [1/3]

template<typename T>
fcppt::optional::object< T >::object ( )

Constructs an empty optional.

Postcondition
has_value() will be false.

◆ object() [2/3]

template<typename T>
fcppt::optional::object< T >::object ( T const &  )
explicit

Constructs an optional by copying.

◆ object() [3/3]

template<typename T>
fcppt::optional::object< T >::object ( T &&  )
explicit

Constructs an optional by moving.

Member Function Documentation

◆ get_unsafe() [1/2]

template<typename T>
T& fcppt::optional::object< T >::get_unsafe ( )

Returns a reference to the current value.

Warning
The behaviour is undefined if has_value() is false

◆ get_unsafe() [2/2]

template<typename T>
T const& fcppt::optional::object< T >::get_unsafe ( ) const

Returns a const reference to the current value.

Warning
The behaviour is undefined if has_value() is false

◆ has_value()

template<typename T>
bool fcppt::optional::object< T >::has_value ( ) const

Returns whether the optional holds a value.