A C++ template library for embedded applications
Designed and maintained by
Aster Consulting Ltd

optional

A class where the value is optional.
If a value is not assigned then an object of the contained type is not constructed.

etl::optional<T>

If _DEBUG is defined then accesses to invalid data is detected either by throwing (ETL_THROW_EXCEPTIONS defined) or
calling the error handler.

Constructor

optional()
Default constructor.

optional(T value)
Construct from value. Constructs a T.

optional(const optional<T>& other)
Construct copy.  Constructs a T.

optional(nullopt)
Construct empty value (same as default constructor).

~optional()
Destructor. Destructs a T if a value has been assigned.

Operations

optional& operator =(etl::nullopt)

optional& operator =(const optional<T>& value)

optional& operator =(const T& value)

Observers

const T& value() const;
T& value();
Returns the contained value.
template <typename T >
T value_or( T value) const;
template <typename T>
T value_or(T value);
Returns the contained value if *this is valid, otherwise returns value.

explicit operator bool() const;
Checks whether *this is in a valid state, i.e. whether the contained value is initialised.

const T* operator->() const;
T* operator->();
Returns a pointer to the contained value.
const T& operator *() const;
T* operator *();
Returns a reference to the contained value.
optional.h