Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
TRetainedRef< T > Struct Template Reference

#include <RetainedRef.h>

Public Member Functions

 TRetainedRef (T &InRef)
 
 TRetainedRef (const T &InRef)=delete
 
 TRetainedRef (T &&InRef)=delete
 
 TRetainedRef (const T &&InRef)=delete
 
 operator T& () const
 
TGet () const
 

Private Attributes

TRef
 

Detailed Description

template<typename T>
struct TRetainedRef< T >

TRetainedRef<T>

A helper class which replaces T& as a function parameter when the reference is intended to be retained by the function (e.g. as a class member). The benefit of this class is that it is a compile error to pass an rvalue which might otherwise bind to a const reference, which is dangerous when the reference is retained.

Example:

struct FRaiiType { explicit FRaiiType(const FThing& InThing) : Ref(InThing) { }

void DoSomething() { Ref.Something(); }

FThing& Ref; };

void Test() { FThing Thing(...); FRaiiType Raii1(Thing); // Compiles Raii.DoSomething(); // Fine

FRaiiType Raii2(FThing(...)); // Compiles Raii.DoSomething(); // Illegal - reference has expired! }

But if the constructor is changed to use TRetainedRef then it fixes that problem:

struct FRaiiType { explicit FRaiiType(TRetainedRef<const FThing> InThing) : Ref(InThing) { }

... }

FThing Thing(...); FRaiiType Raii1(Thing); // Compiles Raii.DoSomething(); // Fine

FRaiiType Raii2(FThing(...)); // Compile error! Raii.DoSomething();

Definition at line 61 of file RetainedRef.h.

Constructor & Destructor Documentation

◆ TRetainedRef() [1/4]

template<typename T >
TRetainedRef< T >::TRetainedRef ( T & InRef)
inline

Definition at line 63 of file RetainedRef.h.

◆ TRetainedRef() [2/4]

template<typename T >
TRetainedRef< T >::TRetainedRef ( const T & InRef)
delete

◆ TRetainedRef() [3/4]

template<typename T >
TRetainedRef< T >::TRetainedRef ( T && InRef)
delete

◆ TRetainedRef() [4/4]

template<typename T >
TRetainedRef< T >::TRetainedRef ( const T && InRef)
delete

Member Function Documentation

◆ Get()

template<typename T >
T & TRetainedRef< T >::Get ( ) const
inline

Definition at line 79 of file RetainedRef.h.

◆ operator T&()

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

Definition at line 74 of file RetainedRef.h.

Member Data Documentation

◆ Ref

template<typename T >
T& TRetainedRef< T >::Ref
private

Definition at line 85 of file RetainedRef.h.


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