Hermes
hermes::Optional< T > Class Template Reference

Works just as std::optional, but supports GPU code. It may contain a value or not. More...

Public Member Functions

HERMES_DEVICE_CALLABLE Optional ()
 Default constructor.
 
HERMES_DEVICE_CALLABLE Optional (const T &v)
 Value constructor. More...
 
HERMES_DEVICE_CALLABLE Optional (T &&v)
 Move value constructor. More...
 
HERMES_DEVICE_CALLABLE Optional (const Optional &other)
 Copy constructor. More...
 
HERMES_DEVICE_CALLABLE Optional (Optional &&other) noexcept
 Move constructor. More...
 
HERMES_DEVICE_CALLABLE operator bool () const
 Casts to bool (indicates whether this contains value) More...
 
HERMES_DEVICE_CALLABLE Optionaloperator= (const Optional &other)
 Copy assignment. More...
 
HERMES_DEVICE_CALLABLE Optionaloperator= (Optional &&other) noexcept
 Move assinment. More...
 
HERMES_DEVICE_CALLABLE Optionaloperator= (const T &v)
 Value assignment. More...
 
HERMES_DEVICE_CALLABLE Optionaloperator= (T &&v)
 Move value assignment. More...
 
HERMES_DEVICE_CALLABLE T * operator-> ()
 Gets value pointer. More...
 
HERMES_DEVICE_CALLABLE const T * operator-> () const
 Gets const value pointer. More...
 
HERMES_DEVICE_CALLABLE T & operator* ()
 Gets value reference. More...
 
HERMES_DEVICE_CALLABLE const T & operator* () const
 Gets value const reference. More...
 
HERMES_DEVICE_CALLABLE void reset ()
 Destroys stored value (if present)
 
HERMES_DEVICE_CALLABLE bool hasValue () const
 Checks if this holds a value. More...
 
HERMES_DEVICE_CALLABLEvalueOr (const T &v) const
 Gets value copy (if present) More...
 
HERMES_DEVICE_CALLABLE T & value ()
 Gets value's reference. More...
 
HERMES_DEVICE_CALLABLE const T & value () const
 Gets value's const reference. More...
 

Detailed Description

template<typename T>
class hermes::Optional< T >

Works just as std::optional, but supports GPU code. It may contain a value or not.

  • Example:
    Optional<int> a;
    // check if a is currently holding an int
    if(a.hasValue()) {}
    // assign a value to a
    a = 1;
    // access like this
    a.value();
    // if you are not sure if value is there, you can access this way
    a.valueOr(-1); // you will get -1 if there is no value in a
Template Parameters
T

Constructor & Destructor Documentation

◆ Optional() [1/4]

template<typename T >
HERMES_DEVICE_CALLABLE hermes::Optional< T >::Optional ( const T &  v)
inlineexplicit

Value constructor.

Parameters
v

◆ Optional() [2/4]

template<typename T >
HERMES_DEVICE_CALLABLE hermes::Optional< T >::Optional ( T &&  v)
inlineexplicit

Move value constructor.

Parameters
v

◆ Optional() [3/4]

template<typename T >
HERMES_DEVICE_CALLABLE hermes::Optional< T >::Optional ( const Optional< T > &  other)
inline

Copy constructor.

Parameters
other

◆ Optional() [4/4]

template<typename T >
HERMES_DEVICE_CALLABLE hermes::Optional< T >::Optional ( Optional< T > &&  other)
inlinenoexcept

Move constructor.

Parameters
other

Member Function Documentation

◆ hasValue()

template<typename T >
HERMES_DEVICE_CALLABLE bool hermes::Optional< T >::hasValue ( ) const
inline

Checks if this holds a value.

Returns

◆ operator bool()

template<typename T >
HERMES_DEVICE_CALLABLE hermes::Optional< T >::operator bool ( ) const
inlineexplicit

Casts to bool (indicates whether this contains value)

Returns

◆ operator*() [1/2]

template<typename T >
HERMES_DEVICE_CALLABLE T& hermes::Optional< T >::operator* ( )
inline

Gets value reference.

Returns

◆ operator*() [2/2]

template<typename T >
HERMES_DEVICE_CALLABLE const T& hermes::Optional< T >::operator* ( ) const
inline

Gets value const reference.

Returns

◆ operator->() [1/2]

template<typename T >
HERMES_DEVICE_CALLABLE T* hermes::Optional< T >::operator-> ( )
inline

Gets value pointer.

Returns

◆ operator->() [2/2]

template<typename T >
HERMES_DEVICE_CALLABLE const T* hermes::Optional< T >::operator-> ( ) const
inline

Gets const value pointer.

Returns

◆ operator=() [1/4]

template<typename T >
HERMES_DEVICE_CALLABLE Optional& hermes::Optional< T >::operator= ( const Optional< T > &  other)
inline

Copy assignment.

Parameters
other
Returns

◆ operator=() [2/4]

template<typename T >
HERMES_DEVICE_CALLABLE Optional& hermes::Optional< T >::operator= ( const T &  v)
inline

Value assignment.

Parameters
v
Returns

◆ operator=() [3/4]

template<typename T >
HERMES_DEVICE_CALLABLE Optional& hermes::Optional< T >::operator= ( Optional< T > &&  other)
inlinenoexcept

Move assinment.

Parameters
other
Returns

◆ operator=() [4/4]

template<typename T >
HERMES_DEVICE_CALLABLE Optional& hermes::Optional< T >::operator= ( T &&  v)
inline

Move value assignment.

Parameters
v
Returns

◆ value() [1/2]

template<typename T >
HERMES_DEVICE_CALLABLE T& hermes::Optional< T >::value ( )
inline

Gets value's reference.

Returns

◆ value() [2/2]

template<typename T >
HERMES_DEVICE_CALLABLE const T& hermes::Optional< T >::value ( ) const
inline

Gets value's const reference.

Returns

◆ valueOr()

template<typename T >
HERMES_DEVICE_CALLABLE T hermes::Optional< T >::valueOr ( const T &  v) const
inline

Gets value copy (if present)

Parameters
vvalue returned in case of empty
Returns

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