DF-0
DF-0: Data processing Framework with Zero-overhead
Loading...
Searching...
No Matches
df0::ref_or_owned< T > Class Template Reference

A utility class that simplifies declaring function attributes that need to be stored without requiring the user to create a shared pointer. More...

#include <ref_or_owned.h>

Public Member Functions

 ref_or_owned (ref_or_owned< T > &&other) noexcept
 ref_or_owned (const ref_or_owned< T > &other)
ref_or_owned & operator= (const ref_or_owned< T > &other)
 Copy assignment operator.
ref_or_owned & operator= (ref_or_owned< T > &&other) noexcept
 Move assignment operator.
template<ref_or_owned_compatible< T > U>
 ref_or_owned (U &value)
 Constructs a ref_or_owned object from a reference to an object.
template<ref_or_owned_compatible< T > U>
 ref_or_owned (U &&value)
 Constructs a ref_or_owned object from a temporary object.
template<ref_or_owned_compatible< T > U>
 ref_or_owned (std::shared_ptr< U > ptr)
const T & get () const
 Returns a const reference to the stored object, regardless of whether it is stored as a reference or a shared pointer.
T & get ()
 Returns a non-const reference to the stored object, regardless of whether it is stored as a reference or a shared pointer.
std::shared_ptr< T > to_shared_ptr () const

Detailed Description

template<typename T>
class df0::ref_or_owned< T >

A utility class that simplifies declaring function attributes that need to be stored without requiring the user to create a shared pointer.

The ref_or_owned class is designed to make it easy to declare function parameters that need to store a value, without requiring the user to manually manage the memory. It acts as a "sink" that can accept either a reference or a temporary object, and will automatically manage the memory for the user.

Template Parameters
TThe type of the object being stored.

Definition at line 31 of file ref_or_owned.h.

Constructor & Destructor Documentation

◆ ref_or_owned() [1/5]

template<typename T>
df0::ref_or_owned< T >::ref_or_owned ( ref_or_owned< T > && other)
inlinenoexcept

Definition at line 37 of file ref_or_owned.h.

◆ ref_or_owned() [2/5]

template<typename T>
df0::ref_or_owned< T >::ref_or_owned ( const ref_or_owned< T > & other)
inline

Definition at line 41 of file ref_or_owned.h.

◆ ref_or_owned() [3/5]

template<typename T>
template<ref_or_owned_compatible< T > U>
df0::ref_or_owned< T >::ref_or_owned ( U & value)
inline

Constructs a ref_or_owned object from a reference to an object.

The object is stored as a reference, and the ref_or_owned object will not manage its memory.

Parameters
valueThe object to be stored.

Definition at line 65 of file ref_or_owned.h.

◆ ref_or_owned() [4/5]

template<typename T>
template<ref_or_owned_compatible< T > U>
df0::ref_or_owned< T >::ref_or_owned ( U && value)
inline

Constructs a ref_or_owned object from a temporary object.

The object is stored as a shared pointer, and the ref_or_owned object will manage its memory.

Parameters
valueThe object to be stored.

Definition at line 77 of file ref_or_owned.h.

◆ ref_or_owned() [5/5]

template<typename T>
template<ref_or_owned_compatible< T > U>
df0::ref_or_owned< T >::ref_or_owned ( std::shared_ptr< U > ptr)
inline

Definition at line 82 of file ref_or_owned.h.

Member Function Documentation

◆ get() [1/2]

template<typename T>
T & df0::ref_or_owned< T >::get ( )
inline

Returns a non-const reference to the stored object, regardless of whether it is stored as a reference or a shared pointer.

Returns
A non-const reference to the stored object.

Definition at line 100 of file ref_or_owned.h.

◆ get() [2/2]

template<typename T>
const T & df0::ref_or_owned< T >::get ( ) const
inline

Returns a const reference to the stored object, regardless of whether it is stored as a reference or a shared pointer.

Returns
A const reference to the stored object.

Definition at line 91 of file ref_or_owned.h.

◆ operator=() [1/2]

template<typename T>
ref_or_owned & df0::ref_or_owned< T >::operator= ( const ref_or_owned< T > & other)
inline

Copy assignment operator.

Definition at line 46 of file ref_or_owned.h.

◆ operator=() [2/2]

template<typename T>
ref_or_owned & df0::ref_or_owned< T >::operator= ( ref_or_owned< T > && other)
inlinenoexcept

Move assignment operator.

Definition at line 52 of file ref_or_owned.h.

◆ to_shared_ptr()

template<typename T>
std::shared_ptr< T > df0::ref_or_owned< T >::to_shared_ptr ( ) const
inline

Definition at line 104 of file ref_or_owned.h.


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