CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
utils::OptionalReference< T > Class Template Reference

A helper class modelled on std::optional that represents an optional T&. More...

#include <utils.hh>

Public Member Functions

 OptionalReference (T &value)
 Construct the optional wrapper from a real value.
 OptionalReference (std::nullptr_t)
 Construct the optional wrapper from not-present value.
value_or (T defaultValue)
 Returns a copy of the wrapped value if present or the provided default value if not.
T & value_or (T &defaultValue)
 Returns a reference to the wrapped value if present or the provided default value if not.
auto and_then (auto &&f)
 If this object holds a value then apply f to it and return the result, otherwise return the result of converting nullptr to the return type of f.

Detailed Description

template<typename T>
class utils::OptionalReference< T >

A helper class modelled on std::optional that represents an optional T&.

This is stored as a pointer with nullptr representing the not-present version.

Unlike std::optional, this intentionally omits the APIs that make it possible to access the value without checking that it is present.

This is intended to be used as an alternative to using bare pointers to represent T& | None.

Definition at line 75 of file utils.hh.

Constructor & Destructor Documentation

◆ OptionalReference() [1/2]

template<typename T>
utils::OptionalReference< T >::OptionalReference ( T & value)
inline

Construct the optional wrapper from a real value.

Definition at line 84 of file utils.hh.

◆ OptionalReference() [2/2]

template<typename T>
utils::OptionalReference< T >::OptionalReference ( std::nullptr_t )
inline

Construct the optional wrapper from not-present value.

Definition at line 89 of file utils.hh.

Member Function Documentation

◆ and_then()

template<typename T>
auto utils::OptionalReference< T >::and_then ( auto && f)
inline

If this object holds a value then apply f to it and return the result, otherwise return the result of converting nullptr to the return type of f.

Definition at line 122 of file utils.hh.

◆ value_or() [1/2]

template<typename T>
T & utils::OptionalReference< T >::value_or ( T & defaultValue)
inline

Returns a reference to the wrapped value if present or the provided default value if not.

Definition at line 108 of file utils.hh.

◆ value_or() [2/2]

template<typename T>
T utils::OptionalReference< T >::value_or ( T defaultValue)
inline

Returns a copy of the wrapped value if present or the provided default value if not.

Definition at line 95 of file utils.hh.


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