F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Fw::Optional< T > Class Template Reference

A type-safe container for an optional value. More...

#include <Fw/Types/Optional.hpp>

Public Member Functions

constexpr Optional ()
 Construct an empty Optional. More...
 
constexpr Optional (const None_t &a)
 Construct an empty Optional from NONE sentinel. More...
 
constexpr Optional (const T &t)
 Construct an Optional containing a value. More...
 
 Optional (const Optional &other)
 Copy constructor. More...
 
 ~Optional ()=default
 Destructor (trivial — T must be trivially copyable) More...
 
bool has_value () const
 
T & value ()
 
const T & value () const
 
value_or (const T &default_value) const
 
void reset ()
 Reset the Optional to an empty state. More...
 
Optionaloperator= (const T &t)
 Assign a value into the Optional. More...
 
Optionaloperator= (const None_t &a)
 Reset the Optional via NONE assignment. More...
 
Optionaloperator= (const Optional &other)
 Copy assignment operator. More...
 
bool operator== (const None_t &a) const
 Compare with NONE sentinel. More...
 
bool operator!= (const None_t &a) const
 Compare with NONE sentinel (inequality) More...
 
bool operator== (const Optional &other) const
 Equality comparison with another Optional. More...
 
bool operator!= (const Optional &other) const
 Inequality comparison with another Optional. More...
 

Detailed Description

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

A type-safe container for an optional value.

Provides a C++14-compatible alternative to std::optional. Only supports trivially copyable types (no non-trivial constructors, destructors, or copy/move operators).

Template Parameters
TThe type of the contained value. Must be trivially copyable.

Definition at line 43 of file Optional.hpp.

Constructor & Destructor Documentation

◆ Optional() [1/4]

template<typename T>
constexpr Fw::Optional< T >::Optional ( )
inline

Construct an empty Optional.

Definition at line 55 of file Optional.hpp.

◆ Optional() [2/4]

template<typename T>
constexpr Fw::Optional< T >::Optional ( const None_t a)
inline

Construct an empty Optional from NONE sentinel.

Definition at line 58 of file Optional.hpp.

◆ Optional() [3/4]

template<typename T>
constexpr Fw::Optional< T >::Optional ( const T &  t)
inline

Construct an Optional containing a value.

Definition at line 61 of file Optional.hpp.

◆ Optional() [4/4]

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

Copy constructor.

Definition at line 64 of file Optional.hpp.

◆ ~Optional()

template<typename T>
Fw::Optional< T >::~Optional ( )
default

Destructor (trivial — T must be trivially copyable)

Member Function Documentation

◆ has_value()

template<typename T>
bool Fw::Optional< T >::has_value ( ) const
inline

Check whether the Optional contains a value

Returns
true if a value is present

Definition at line 79 of file Optional.hpp.

◆ operator!=() [1/2]

template<typename T>
bool Fw::Optional< T >::operator!= ( const None_t a) const
inline

Compare with NONE sentinel (inequality)

Definition at line 147 of file Optional.hpp.

◆ operator!=() [2/2]

template<typename T>
bool Fw::Optional< T >::operator!= ( const Optional< T > &  other) const
inline

Inequality comparison with another Optional.

Definition at line 164 of file Optional.hpp.

◆ operator=() [1/3]

template<typename T>
Optional& Fw::Optional< T >::operator= ( const T &  t)
inline

Assign a value into the Optional.

Definition at line 113 of file Optional.hpp.

◆ operator=() [2/3]

template<typename T>
Optional& Fw::Optional< T >::operator= ( const None_t a)
inline

Reset the Optional via NONE assignment.

Definition at line 120 of file Optional.hpp.

◆ operator=() [3/3]

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

Copy assignment operator.

Definition at line 127 of file Optional.hpp.

◆ operator==() [1/2]

template<typename T>
bool Fw::Optional< T >::operator== ( const None_t a) const
inline

Compare with NONE sentinel.

Definition at line 141 of file Optional.hpp.

◆ operator==() [2/2]

template<typename T>
bool Fw::Optional< T >::operator== ( const Optional< T > &  other) const
inline

Equality comparison with another Optional.

Definition at line 153 of file Optional.hpp.

◆ reset()

template<typename T>
void Fw::Optional< T >::reset ( )
inline

Reset the Optional to an empty state.

Definition at line 106 of file Optional.hpp.

◆ value() [1/2]

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

Access the contained value

Precondition
has_value() must be true
Returns
Mutable reference to the contained value

Definition at line 84 of file Optional.hpp.

◆ value() [2/2]

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

Access the contained value (const)

Precondition
has_value() must be true
Returns
Const reference to the contained value

Definition at line 92 of file Optional.hpp.

◆ value_or()

template<typename T>
T Fw::Optional< T >::value_or ( const T &  default_value) const
inline

Access the value or return a default

Returns
The contained value if present, otherwise the provided default

Definition at line 99 of file Optional.hpp.


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