A C++ template library for embedded applications
Designed and maintained by
Aster Consulting Ltd
Join the ETL community

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.

____________________________________________________________________________________________________

Non-member functions


==  true if the contents are equal, otherwise false.
!=  true if the contents are not equal, otherwise false.
<   true if the contents of the lhs are less than the contents of the rhs,  otherwise false.
<=  true if the contents of the lhs are less than or equal to the contents of the rhs, otherwise false.
>   true if the contents of the lhs are greater than the contents of the rhs,  otherwise false.
>=  true if the contents of the lhs are greater than or equal to the contents of the rhs, otherwise false.
optional.h