Public Types | Public Member Functions
efl::eina::optional< T > Struct Template Reference

This class manages an optional contained value, i.e. More...

Public Types

typedef optional< T > _self_type
 Type for the optional class itself. More...
 

Public Member Functions

constexpr optional (std::nullptr_t)
 Create a disengaged object. More...
 
constexpr optional ()
 Default constructor. More...
 
 optional (T &&other)
 Create an engaged object by moving other content. More...
 
 optional (T const &other)
 Create an engaged object by copying other content. More...
 
template<typename U >
 optional (U &&other, typename std::enable_if< std::is_convertible< U, T >::value >::type *=0)
 Create an engaged object by moving other content. More...
 
template<typename U >
 optional (U const &other, typename std::enable_if< std::is_convertible< U, T >::value >::type *=0)
 Create an engaged object by copying other content. More...
 
 optional (optional< T > const &other)
 Copy constructor. More...
 
 optional (optional< T > &&other)
 Move constructor. More...
 
template<typename U >
 optional (optional< U > &&other, typename std::enable_if< std::is_convertible< U, T >::value >::type *=0)
 Move constructor. More...
 
template<typename U >
 optional (optional< U > const &other, typename std::enable_if< std::is_convertible< U, T >::value >::type *=0)
 Copy constructor. More...
 
_self_typeoperator= (optional< T > &&other)
 Assign new content to the object. More...
 
_self_typeoperator= (optional< T >const &other)
 Assign new content to the object. More...
 
template<typename U >
std::enable_if< std::is_convertible< U, T >::value, _self_type >::type & operator= (optional< U > &&other)
 Assign new content to the object. More...
 
template<typename U >
std::enable_if< std::is_convertible< U, T >::value, _self_type >::type & operator= (optional< U >const &other)
 Assign new content to the object. More...
 
void disengage ()
 Disengage the object, destroying the current contained value, if any.
 
 ~optional ()
 Releases the contained value if the object is engaged.
 
 operator bool () const
 Convert to bool based on whether the object is engaged or not. More...
 
bool operator! () const
 Convert to bool based on whether the object is engaged or not. More...
 
T * operator-> ()
 Access member of the contained value. More...
 
T const * operator-> () const
 Access constant member of the contained value. More...
 
T & operator* ()
 Get the contained value. More...
 
T const & operator* () const
 Get the contained value. More...
 
T & get ()
 Get the contained value. More...
 
T const & get () const
 Get the contained value. More...
 
void swap (optional< T > &other)
 Swap content with another eina::optional object. More...
 
bool is_engaged () const
 Check if the object is engaged. More...
 

Detailed Description

template<typename T>
struct efl::eina::optional< T >

This class manages an optional contained value, i.e.

a value that semantically may not be present.

A common use case for optional is the return value of a function that may fail. As opposed to other approaches, such as std::pair<T,bool>, optional handles expensive to construct objects well and is more readable, as the intent is expressed explicitly.

An optional object holding a semantically present value is considered to be engaged, otherwise it is considered to be disengaged.

Member Typedef Documentation

◆ _self_type

template<typename T>
typedef optional<T> efl::eina::optional< T >::_self_type

Type for the optional class itself.

Constructor & Destructor Documentation

◆ optional() [1/10]

template<typename T>
constexpr efl::eina::optional< T >::optional ( std::nullptr_t  )
inline

Create a disengaged object.

This constructor creates a disengaged eina::optional object.

◆ optional() [2/10]

template<typename T>
constexpr efl::eina::optional< T >::optional ( )
inline

Default constructor.

Create a disengaged object.

◆ optional() [3/10]

template<typename T>
efl::eina::optional< T >::optional ( T &&  other)
inline

Create an engaged object by moving other content.

Parameters
otherR-value reference to the desired type.

This constructor creates an eina::optional object in an engaged state. The contained value is initialized by moving other.

◆ optional() [4/10]

template<typename T>
efl::eina::optional< T >::optional ( T const &  other)
inline

Create an engaged object by copying other content.

Parameters
otherConstant reference to the desired type.

This constructor creates an eina::optional object in an engaged state. The contained value is initialized by copying other.

◆ optional() [5/10]

template<typename T>
template<typename U >
efl::eina::optional< T >::optional ( U &&  other,
typename std::enable_if< std::is_convertible< U, T >::value >::type *  = 0 
)
inline

Create an engaged object by moving other content.

Parameters
otherR-value reference to the desired type.

This constructor creates an eina::optional object in an engaged state. The contained value is initialized by moving other.

◆ optional() [6/10]

template<typename T>
template<typename U >
efl::eina::optional< T >::optional ( U const &  other,
typename std::enable_if< std::is_convertible< U, T >::value >::type *  = 0 
)
inline

Create an engaged object by copying other content.

Parameters
otherConstant reference to the desired type.

This constructor creates an eina::optional object in an engaged state. The contained value is initialized by copying other.

◆ optional() [7/10]

template<typename T>
efl::eina::optional< T >::optional ( optional< T > const &  other)
inline

Copy constructor.

Create an object containing the same value as other and in the same state.

Parameters
otherConstant reference to another eina::optional object that holds the same value type.

This constructor creates an eina::optional object with the same engagement state of other. If other is engaged then the contained value of the newly created object is initialized by copying the contained value of other.

◆ optional() [8/10]

template<typename T>
efl::eina::optional< T >::optional ( optional< T > &&  other)
inline

Move constructor.

Create an object containing the same value as other and in the same state.

Parameters
otherR-value reference to another eina::optional object that holds the same value type.

This constructor creates an eina::optional object with the same engagement state of other. If other is engaged then the contained value of the newly created object is initialized by moving the contained value of other.

◆ optional() [9/10]

template<typename T>
template<typename U >
efl::eina::optional< T >::optional ( optional< U > &&  other,
typename std::enable_if< std::is_convertible< U, T >::value >::type *  = 0 
)
inline

Move constructor.

Create an object containing the same value as other and in the same state.

Parameters
otherR-value reference to another eina::optional object that holds a different, but convertible, value type.

This constructor creates an eina::optional object with the same engagement state of other. If other is engaged then the contained value of the newly created object is initialized by moving the contained value of other.

◆ optional() [10/10]

template<typename T>
template<typename U >
efl::eina::optional< T >::optional ( optional< U > const &  other,
typename std::enable_if< std::is_convertible< U, T >::value >::type *  = 0 
)
inline

Copy constructor.

Create an object containing the same value as other and in the same state.

Parameters
otherConstant reference to another eina::optional object that holds a different, but convertible, value type.

This constructor creates an eina::optional object with the same engagement state of other. If other is engaged then the contained value of the newly created object is initialized by converting and copying the contained value of other.

References efl::eina::optional< T >::is_engaged().

Member Function Documentation

◆ operator=() [1/4]

template<typename T>
_self_type& efl::eina::optional< T >::operator= ( optional< T > &&  other)
inline

Assign new content to the object.

Parameters
otherR-value reference to another eina::optional object that holds the same value type.

This operator replaces the current content of the object. If other is engaged its contained value is moved to this object, making *this be considered engaged too. If other is disengaged *this is also made disengaged and its contained value, if any, is simple destroyed.

◆ operator=() [2/4]

template<typename T>
_self_type& efl::eina::optional< T >::operator= ( optional< T >const &  other)
inline

Assign new content to the object.

Parameters
otherConstant reference to another eina::optional object that holds the same value type.

This operator replaces the current content of the object. If other is engaged its contained value is copied to this object, making *this be considered engaged too. If other is disengaged *this is also made disengaged and its contained value, if any, is simple destroyed.

References efl::eina::optional< T >::swap().

◆ operator=() [3/4]

template<typename T>
template<typename U >
std::enable_if<std::is_convertible<U, T>::value, _self_type>::type& efl::eina::optional< T >::operator= ( optional< U > &&  other)
inline

Assign new content to the object.

Parameters
otherR-value reference to another eina::optional object that holds a different, but convertible, value type.

This operator replaces the current content of the object. If other is engaged its contained value is moved to this object, making *this be considered engaged too. If other is disengaged *this is also made disengaged and its contained value, if any, is simple destroyed.

◆ operator=() [4/4]

template<typename T>
template<typename U >
std::enable_if<std::is_convertible<U, T>::value, _self_type>::type& efl::eina::optional< T >::operator= ( optional< U >const &  other)
inline

Assign new content to the object.

Parameters
otherConstant reference to another eina::optional object that holds a different, but convertible, value type.

This operator replaces the current content of the object. If other is engaged its contained value is converted and copied to this object, making *this be considered engaged too. If other is disengaged *this is also made disengaged and its contained value, if any, is simple destroyed.

References efl::eina::optional< T >::is_engaged().

◆ operator bool()

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

Convert to bool based on whether the object is engaged or not.

Returns
true if the object is engaged, false otherwise.

◆ operator!()

template<typename T>
bool efl::eina::optional< T >::operator! ( ) const
inline

Convert to bool based on whether the object is engaged or not.

Returns
true if the object is disengaged, false otherwise.

◆ operator->() [1/2]

template<typename T>
T* efl::eina::optional< T >::operator-> ( )
inline

Access member of the contained value.

Returns
Pointer to the contained value, whose member will be accessed.

◆ operator->() [2/2]

template<typename T>
T const* efl::eina::optional< T >::operator-> ( ) const
inline

Access constant member of the contained value.

Returns
Constant pointer to the contained value, whose member will be accessed.

◆ operator*() [1/2]

template<typename T>
T& efl::eina::optional< T >::operator* ( )
inline

Get the contained value.

Returns
Reference to the contained value.

◆ operator*() [2/2]

template<typename T>
T const& efl::eina::optional< T >::operator* ( ) const
inline

Get the contained value.

Returns
Constant reference to the contained value.

◆ get() [1/2]

template<typename T>
T& efl::eina::optional< T >::get ( )
inline

Get the contained value.

Returns
Reference to the contained value.

◆ get() [2/2]

template<typename T>
T const& efl::eina::optional< T >::get ( ) const
inline

Get the contained value.

Returns
Constant reference to the contained value.

◆ swap()

template<typename T>
void efl::eina::optional< T >::swap ( optional< T > &  other)
inline

Swap content with another eina::optional object.

Parameters
otherAnother eina::optional object.

References efl::eina::optional< T >::is_engaged().

Referenced by efl::eina::optional< T >::operator=(), and efl::eina::swap().

◆ is_engaged()

template<typename T>
bool efl::eina::optional< T >::is_engaged ( ) const
inline

Check if the object is engaged.

Returns
true if the object is currently engaged, false otherwise.

Referenced by efl::eina::optional< T >::operator=(), efl::eina::optional< T >::optional(), and efl::eina::optional< T >::swap().