2.6.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.

Template Parameters
TThe type to make optional, which must be CopyConstructible or Movable, Assignable or AssignMovable 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...
 
typedef T & reference
 The non const reference type to value_type More...
 
typedef T const & const_reference
 The const reference type to value_type More...
 

Public Member Functions

 object ()
 Constructs an empty optional. More...
 
 object (const_reference ref)
 Constructs an optional from a const_reference. More...
 
 object (T &&ref)
 Constructs an optional by moving from an rvalue reference. More...
 
 object (object const &other)
 Copy constructs an optional. More...
 
 object (object &&other) noexcept(std::is_nothrow_move_constructible< T >::value)
 Move constructs an optional. More...
 
objectoperator= (object const &other)
 Assigns from an optional. More...
 
objectoperator= (object &&other) noexcept(std::is_nothrow_move_constructible< T >::value &&std::is_nothrow_move_assignable< T >::value)
 Move assigns from an optional. More...
 
 ~object ()
 Destroys the value, if any. More...
 
reference get_unsafe ()
 Returns a reference to the current value. More...
 
const_reference 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

◆ const_reference

template<typename T>
typedef T const& fcppt::optional::object< T >::const_reference

The const reference type to value_type

◆ reference

template<typename T>
typedef T& fcppt::optional::object< T >::reference

The non const reference type to value_type

◆ value_type

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

The value type.

Constructor & Destructor Documentation

◆ object() [1/5]

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

Constructs an empty optional.

Postcondition
has_value() will be false.

◆ object() [2/5]

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

Constructs an optional from a const_reference.

Constructs an optional by copying from ref.

Parameters
refThe value to initialize the optional with
Postcondition
has_value() will be true.

◆ object() [3/5]

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

Constructs an optional by moving from an rvalue reference.

Constructs an optional by moving from ref

Parameters
refThe value to move from
Postcondition
has_value() will be true

◆ object() [4/5]

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

Copy constructs an optional.

Constructs an optional by copying from other if other.has_value() is true. Otherwise, the new optional will have no value.

Parameters
otherThe optional to copy from

◆ object() [5/5]

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

Move constructs an optional.

Constructs an optional by moving from other. In any case, other will be left uninitialized.

Parameters
otherThe optional to move from

◆ ~object()

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

Destroys the value, if any.

If has_value() is true then the current value will be destroyed

Member Function Documentation

◆ get_unsafe() [1/2]

template<typename T>
reference 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>
const_reference 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.

◆ operator=() [1/2]

template<typename T>
object& fcppt::optional::object< T >::operator= ( object< T > const &  other)

Assigns from an optional.

Assigns the current value from *other if has_value() and other.has_value() are true. Otherwise, if has_value() is false, then the current value will be copy constructed from *other. Otherwise, if other.has_value() is false, then the optional will be reset.

Parameters
otherThe optional to assign from
Returns
*this

◆ operator=() [2/2]

template<typename T>
object& fcppt::optional::object< T >::operator= ( object< T > &&  other) const &&
noexcept

Move assigns from an optional.

Moves the current value from *other if has_value() and other.has_value() are true. Otherwise, if has_value() is false, then the current value will be move constructed from *other. Otherwise, if other.has_value() is false, then the optional will be reset.

Parameters
otherThe optional to move assign from
Returns
*this