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

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

#include <src/utils/optional_ref.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 zrythm::utils::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 25 of file optional_ref.h.

Constructor & Destructor Documentation

◆ OptionalRef() [1/2]

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

Definition at line 28 of file optional_ref.h.

◆ OptionalRef() [2/2]

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

Definition at line 29 of file optional_ref.h.

Member Function Documentation

◆ has_value()

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

Check if a value is present.

Returns
true if a value is present, false otherwise.

Definition at line 67 of file optional_ref.h.

◆ operator bool()

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

Definition at line 60 of file optional_ref.h.

◆ operator*() [1/2]

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

Dereference the underlying value.

Returns
A reference to the underlying value.

Definition at line 38 of file optional_ref.h.

◆ operator*() [2/2]

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

Definition at line 43 of file optional_ref.h.

◆ operator->() [1/2]

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

Definition at line 54 of file optional_ref.h.

◆ operator->() [2/2]

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

Definition at line 49 of file optional_ref.h.

◆ value()

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

Get a reference to the underlying value.

Returns
A reference to the underlying value.

Definition at line 74 of file optional_ref.h.

Field Documentation

◆ ref_

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

Definition at line 31 of file optional_ref.h.


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