Woman, Life, Freedom


Adaptive AUTOSAR
ARA public interface header documentation
ara::core::Optional< T > Class Template Reference

A wrapper around a possible value. More...

#include <optional.h>

Public Member Functions

 Optional (const T &value)
 
 Optional (T &&value)
 
 Optional (const Optional &other)
 
 Optional (Optional &&other) noexcept(std::is_nothrow_move_assignable< T >::value)
 
constexpr Optionaloperator= (const Optional &other)
 
constexpr Optionaloperator= (Optional &&other) noexcept(std::is_nothrow_move_assignable< T >::value)
 
template<typename U = T>
constexpr Optionaloperator= (const U &value)
 
template<typename U = T>
constexpr Optionaloperator= (U &&value)
 
template<typename... Args>
void Emplace (Args &&...args)
 Construct a new value from the give argument(s) and assign it to the instance value. More...
 
void Swap (Optional &other) noexcept(std::is_nothrow_move_assignable< T >::value)
 Swap the current instance with another one. More...
 
void Reset () noexcept
 Reset the instance value.
 
constexpr bool HasValue () const noexcept
 Indicate whether the instance has a value or not. More...
 
constexpr operator bool () const noexcept
 
const T & operator* () const &
 
T && operator* () &&
 
const T * operator-> () const
 
const T & Value () const &
 Get instance possible value. More...
 
T && Value () &&
 Get instance possible value. More...
 
template<typename U >
ValueOr (U &&defaultValue) const &
 Get the instance value or the default value. More...
 
template<typename U >
ValueOr (U &&defaultValue) &&
 Get the instance value or the default value. More...
 

Detailed Description

template<typename T>
class ara::core::Optional< T >

A wrapper around a possible value.

Template Parameters
TPossible value type

Member Function Documentation

◆ Emplace()

template<typename T >
template<typename... Args>
void ara::core::Optional< T >::Emplace ( Args &&...  args)
inline

Construct a new value from the give argument(s) and assign it to the instance value.

Parameters
argsArgument(s) to construct a new value

◆ HasValue()

template<typename T >
constexpr bool ara::core::Optional< T >::HasValue ( ) const
inlineconstexprnoexcept

Indicate whether the instance has a value or not.

Returns
True if has a value, otherwise false

◆ operator bool()

template<typename T >
constexpr ara::core::Optional< T >::operator bool ( ) const
inlineexplicitconstexprnoexcept
Returns
True if the instance has a value, otherwise false

◆ operator*() [1/2]

template<typename T >
T && ara::core::Optional< T >::operator* ( ) &&
inline
Returns
Movable value
Exceptions
std::runtime_errorThrows if there is no value

◆ operator*() [2/2]

template<typename T >
const T & ara::core::Optional< T >::operator* ( ) const &
inline
Returns
Copied value
Exceptions
std::runtime_errorThrows if there is no value

◆ operator->()

template<typename T >
const T * ara::core::Optional< T >::operator-> ( ) const
inline
Returns
Constant value pointer
Exceptions
std::runtime_errorThrows if there is no value

◆ Swap()

template<typename T >
void ara::core::Optional< T >::Swap ( Optional< T > &  other)
inlinenoexcept

Swap the current instance with another one.

Parameters
otherAnother Optional for swapping

◆ Value() [1/2]

template<typename T >
T && ara::core::Optional< T >::Value ( ) &&
inline

Get instance possible value.

Returns
Movable value
Exceptions
std::runtime_errorThrows if there is no value

◆ Value() [2/2]

template<typename T >
const T & ara::core::Optional< T >::Value ( ) const &
inline

Get instance possible value.

Returns
Copied value
Exceptions
std::runtime_errorThrows if there is no value

◆ ValueOr() [1/2]

template<typename T >
template<typename U >
T ara::core::Optional< T >::ValueOr ( U &&  defaultValue) &&
inline

Get the instance value or the default value.

Template Parameters
UDefault value type
Parameters
defaultValueValue to be return in absence of the instance value
Returns
Instance value if exists, otherwise the default value

◆ ValueOr() [2/2]

template<typename T >
template<typename U >
T ara::core::Optional< T >::ValueOr ( U &&  defaultValue) const &
inline

Get the instance value or the default value.

Template Parameters
UDefault value type
Parameters
defaultValueValue to be return in absence of the instance value
Returns
Instance value if exists, otherwise the default value