Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
elm::Option< T > Class Template Reference

#include <elm/util/Option.h>

Public Member Functions

 Option (void)
 
 Option (const OptionalNone &none)
 
 Option (T value)
 
 Option (const Option< T > &opt)
 
bool isOne (void) const
 
bool isNone (void) const
 
value (void) const
 
 operator bool (void) const
 
operator* (void) const
 
 operator T (void) const
 
Option< T > & operator= (const Option< T > &opt)
 
Option< T > & operator= (T value)
 

Detailed Description

template<class T>
class elm::Option< T >

This class is very handly to manage parameters or return value that may be optional. This class records there is no value or there is a value and the instance of the value.

To build it, you may be easier to use the special value elm::none or the special function elm::some() instead of the class constructors.
if(cannot_compute)
return none;
else
return some(result);
Please consider the conversion operator allowing to test of the availability of a value by putting it straight-forward in a condition or accessing the value by putting the optional value in place where the value may be used.
Option<int> val = f();
if(val)
x += val;
Parameters
TType of the stored value.

Constructor & Destructor Documentation

template<class T>
elm::Option< T >::Option ( void  )

Build an empty optional value recording there is no value.

template<class T>
elm::Option< T >::Option ( const OptionalNone none)

For nternal use only.

template<class T>
elm::Option< T >::Option ( value)
template<class T>
elm::Option< T >::Option ( const Option< T > &  opt)

Build an optional value by copying an existing one.

Parameters
optOptional value to clone.

Member Function Documentation

template<class T>
bool elm::Option< T >::isNone ( void  ) const

Test if no value is available.

Returns
True if no value is available, false else.
template<class T>
bool elm::Option< T >::isOne ( void  ) const

Test if a value is available.

Returns
True if a value is available, false else.

Referenced by elm::Option< T >::operator bool().

template<class T>
elm::Option< T >::operator bool ( void  ) const
Returns
Evaluates to true if a value is available, false else.

References elm::Option< T >::isOne().

template<class T>
elm::Option< T >::operator T ( void  ) const

Convert to the stored value.

References elm::Option< T >::value().

template<class T>
T elm::Option< T >::operator* ( void  ) const
Returns
The stored value.

References elm::Option< T >::value().

template<class T>
Option< T > & elm::Option< T >::operator= ( const Option< T > &  opt)

Provides assignment support.

Parameters
optOptional value to assign.
Returns
Current object.
template<class T>
Option<T>& elm::Option< T >::operator= ( value)
template<class T>
T elm::Option< T >::value ( void  ) const

Get the value.

Returns
The stored value.
Warning
It is an error to call this method if no value is available.

References elm::asis_t< T >::get().

Referenced by elm::Option< T >::operator T(), and elm::Option< T >::operator*().


The documentation for this class was generated from the following files: