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


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


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


Default constructor.

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

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

Construct empty value (same as default constructor).

Destructor. Destructs a T if a value has been assigned.


optional& operator =(etl::nullopt)

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

optional& operator =(const T& value)


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.