4.6.0
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
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:

  • No operator-> and operator*. This has been replaced get_unsafe.
  • No operator bool(). This has been replaced by has_value.
  • No assignment from T. Assign an optional instead.
Template Parameters
TMust be move constructible.

See fcppt.optional for more information.

Public Types

using std_type = std::optional<T>
 
using value_type = T
 The value type.
 

Public Member Functions

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

Member Typedef Documentation

◆ std_type

template<typename T >
using fcppt::optional::object< T >::std_type = std::optional<T>

◆ value_type

template<typename T >
using fcppt::optional::object< T >::value_type = T

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 ( )
nodiscard

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
nodiscard

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
nodiscard

Returns whether the optional holds a value.

◆ impl() [1/2]

template<typename T >
std_type & fcppt::optional::object< T >::impl ( )
nodiscard

◆ impl() [2/2]

template<typename T >
std_type const & fcppt::optional::object< T >::impl ( ) const
nodiscard