aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
gum::optional_ref< T > Class Template Reference

A lightweight wrapper around a pointer providing an optional-like API for references (not supported by std::optional<T&>). More...

#include <optional_ref.h>

Public Member Functions

 optional_ref () noexcept=default
 optional_ref (std::nullopt_t) noexcept
 optional_ref (T &ref) noexcept
 optional_ref (T &&)=delete
 operator bool () const noexcept
bool has_value () const noexcept
T & value () const
T & operator* () const
T * operator-> () const noexcept

Private Attributes

T * _ptr_ = nullptr

Detailed Description

template<typename T>
class gum::optional_ref< T >

A lightweight wrapper around a pointer providing an optional-like API for references (not supported by std::optional<T&>).

Template Parameters
TThe referenced type.

Definition at line 62 of file optional_ref.h.

Constructor & Destructor Documentation

◆ optional_ref() [1/4]

template<typename T>
gum::optional_ref< T >::optional_ref ( )
defaultnoexcept

References optional_ref().

Referenced by optional_ref(), optional_ref(), and operator bool().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ optional_ref() [2/4]

template<typename T>
gum::optional_ref< T >::optional_ref ( std::nullopt_t )
noexcept

Definition at line 51 of file optional_ref_tpl.h.

51{}

◆ optional_ref() [3/4]

template<typename T>
gum::optional_ref< T >::optional_ref ( T & ref)
noexcept

Definition at line 54 of file optional_ref_tpl.h.

54: _ptr_(&ref) {}
A lightweight wrapper around a pointer providing an optional-like API for references (not supported b...

References _ptr_.

◆ optional_ref() [4/4]

template<typename T>
gum::optional_ref< T >::optional_ref ( T && )
delete

References optional_ref(), has_value(), and value().

Here is the call graph for this function:

Member Function Documentation

◆ has_value()

template<typename T>
bool gum::optional_ref< T >::has_value ( ) const
noexcept

Definition at line 62 of file optional_ref_tpl.h.

62 {
63 return _ptr_ != nullptr;
64 }

References _ptr_.

Referenced by optional_ref().

Here is the caller graph for this function:

◆ operator bool()

template<typename T>
gum::optional_ref< T >::operator bool ( ) const
explicitnoexcept

Definition at line 57 of file optional_ref_tpl.h.

57 {
58 return _ptr_ != nullptr;
59 }

References optional_ref(), and _ptr_.

Here is the call graph for this function:

◆ operator*()

template<typename T>
T & gum::optional_ref< T >::operator* ( ) const

Definition at line 73 of file optional_ref_tpl.h.

73 {
74 return value();
75 }

References value().

Here is the call graph for this function:

◆ operator->()

template<typename T>
T * gum::optional_ref< T >::operator-> ( ) const
noexcept

Definition at line 78 of file optional_ref_tpl.h.

78 {
79 return _ptr_;
80 }

References _ptr_.

◆ value()

template<typename T>
T & gum::optional_ref< T >::value ( ) const

Definition at line 67 of file optional_ref_tpl.h.

67 {
68 if (!_ptr_) throw std::bad_optional_access();
69 return *_ptr_;
70 }

References _ptr_.

Referenced by optional_ref(), and operator*().

Here is the caller graph for this function:

Member Data Documentation

◆ _ptr_

template<typename T>
T* gum::optional_ref< T >::_ptr_ = nullptr
private

Definition at line 63 of file optional_ref.h.

Referenced by optional_ref(), has_value(), operator bool(), operator->(), and value().


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