Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
OptionalRef< T > Struct Template Reference

Wrapper around std::optional<std::reference_wrapper<T>> that provides a more convenient API. More...

#include <src/utils/types.h>

Public Member Functions

 OptionalRef (std::nullopt_t)
 OptionalRef (T &ref)
T & operator* ()
 Dereference the underlying value.
const T & operator* () const
const T * operator-> () const
T * operator-> ()
 operator bool () const
bool has_value () const
 Check if a value is present.
T & value ()
 Get a reference to the underlying value.

Data Fields

std::optional< std::reference_wrapper< T > > ref_

Detailed Description

template<typename T>
struct OptionalRef< T >

Wrapper around std::optional<std::reference_wrapper<T>> that provides a more convenient API.

This class provides a convenient wrapper around std::optional<std::reference_wrapper<T>> that allows you to easily access the underlying value without having to check for the presence of a value first.

The operator*() and value() methods return a reference to the underlying value, and the has_value() method can be used to check if a value is present.

Definition at line 263 of file types.h.

Constructor & Destructor Documentation

◆ OptionalRef() [1/2]

template<typename T>
OptionalRef< T >::OptionalRef ( std::nullopt_t )
inline

Definition at line 266 of file types.h.

◆ OptionalRef() [2/2]

template<typename T>
OptionalRef< T >::OptionalRef ( T & ref)
inline

Definition at line 267 of file types.h.

Member Function Documentation

◆ has_value()

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

Check if a value is present.

Returns
true if a value is present, false otherwise.

Definition at line 305 of file types.h.

◆ operator bool()

template<typename T>
OptionalRef< T >::operator bool ( ) const
inlineexplicit

Definition at line 298 of file types.h.

◆ operator*() [1/2]

template<typename T>
T & OptionalRef< T >::operator* ( )
inline

Dereference the underlying value.

Returns
A reference to the underlying value.

Definition at line 276 of file types.h.

◆ operator*() [2/2]

template<typename T>
const T & OptionalRef< T >::operator* ( ) const
inline

Definition at line 281 of file types.h.

◆ operator->() [1/2]

template<typename T>
T * OptionalRef< T >::operator-> ( )
inline

Definition at line 292 of file types.h.

◆ operator->() [2/2]

template<typename T>
const T * OptionalRef< T >::operator-> ( ) const
inline

Definition at line 287 of file types.h.

◆ value()

template<typename T>
T & OptionalRef< T >::value ( )
inline

Get a reference to the underlying value.

Returns
A reference to the underlying value.

Definition at line 312 of file types.h.

Field Documentation

◆ ref_

template<typename T>
std::optional<std::reference_wrapper<T> > OptionalRef< T >::ref_

Definition at line 269 of file types.h.


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