Safe DDS
eprosima::safedds::memory::Optional< T > Struct Template Reference

Template structure to hold an optional type. More...

#include <Optional.hpp>

Public Member Functions

constexpr bool has_value () const noexcept
 Checks if the optional value is set. More...
 
void set (const T &new_value) noexcept
 Sets the value of the optional. More...
 
const T & value () const &noexcept
 Retrieves the value of the optional. More...
 
const T & value () const &&noexcept=delete
 Deleted const getter on rvalue objects. More...
 
T & inner_reference () &noexcept
 Retrieves a non-const reference to the value of the optional. More...
 
T & inner_reference () const &&noexcept=delete
 Deleted getter on rvalue objects. More...
 
void reset () noexcept
 Resets the optional value. More...
 

Protected Attributes

bool has_value_ = false
 Flag indicating if the optional value is set. More...
 
value_ = {}
 The value of the optional. More...
 

Detailed Description

template<typename T>
struct eprosima::safedds::memory::Optional< T >

Template structure to hold an optional type.

Member Function Documentation

◆ has_value()

template<typename T >
constexpr bool eprosima::safedds::memory::Optional< T >::has_value ( ) const
inlineconstexprnoexcept

Checks if the optional value is set.

Returns
true if the optional value is set, false otherwise.

◆ inner_reference() [1/2]

template<typename T >
T& eprosima::safedds::memory::Optional< T >::inner_reference ( ) &
inlinenoexcept

Retrieves a non-const reference to the value of the optional.

Note
This method does not mark the optional value as set. If the value is modified using the returned reference, set method should be called to mark the value as set.
Returns
A non-const reference to the value of the optional.

◆ inner_reference() [2/2]

template<typename T >
T& eprosima::safedds::memory::Optional< T >::inner_reference ( ) const &&
deletenoexcept

Deleted getter on rvalue objects.

◆ reset()

template<typename T >
void eprosima::safedds::memory::Optional< T >::reset ( )
inlinenoexcept

Resets the optional value.

This function resets the optional value, marking it as not set.

Postcondition
Method has_value returns false.

◆ set()

template<typename T >
void eprosima::safedds::memory::Optional< T >::set ( const T &  new_value)
inlinenoexcept

Sets the value of the optional.

This function sets the value of the optional to the given value.

Parameters
new_valueThe value to set.
Postcondition
Method has_value returns true.

◆ value() [1/2]

template<typename T >
const T& eprosima::safedds::memory::Optional< T >::value ( ) const &&
deletenoexcept

Deleted const getter on rvalue objects.

◆ value() [2/2]

template<typename T >
const T& eprosima::safedds::memory::Optional< T >::value ( ) const &
inlinenoexcept

Retrieves the value of the optional.

This function returns a const reference to the value of the optional.

Note
If the optional value is not set, a fatal error is triggered.
Returns
A const reference to the value of the optional.

Member Data Documentation

◆ has_value_

template<typename T >
bool eprosima::safedds::memory::Optional< T >::has_value_ = false
protected

Flag indicating if the optional value is set.

◆ value_

template<typename T >
T eprosima::safedds::memory::Optional< T >::value_ = {}
protected

The value of the optional.


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