Loading...
Searching...
No Matches
Vdf_FixedSizePolymorphicHolder< Base, BufferSize > Class Template Reference

Used to implement small object optimizations for the type-erasure (Any) pattern. More...

#include <fixedSizePolymorphicHolder.h>

Public Member Functions

 Vdf_FixedSizePolymorphicHolder (Vdf_FixedSizePolymorphicHolder const &)=delete
 
Vdf_FixedSizePolymorphicHolderoperator= (Vdf_FixedSizePolymorphicHolder const &)=delete
 
template<class Derived , class ... Args>
void New (Args &&... args)
 Creates an instance.
 
void Destroy ()
 Destroys a held instance.
 
Base const * Get () const
 Returns a Base pointer to the held instance.
 
Base * Get ()
 Returns a Base pointer to the held instance.
 

Detailed Description

template<class Base, size_t BufferSize>
class Vdf_FixedSizePolymorphicHolder< Base, BufferSize >

Used to implement small object optimizations for the type-erasure (Any) pattern.

This class allows clients to instantiate polymorphic objects into a fixed buffer space. If code attempts to instantiate an object that is too large to fit in the allotted space, that code will generate a compile-time error. Additionally, any instance of a derived class stored in this holder must have its Base object at the same address. Practically speaking, this means that multiple inheritance isn't supported. Currently this requirement is enforced only at runtime.

Definition at line 36 of file fixedSizePolymorphicHolder.h.

Member Function Documentation

◆ Destroy()

void Destroy ( )
inline

Destroys a held instance.

Invokes ~Base on the held object. A valid instance of type Base or a type derived from Base must already be held.

Definition at line 81 of file fixedSizePolymorphicHolder.h.

◆ Get() [1/2]

Base * Get ( )
inline

Returns a Base pointer to the held instance.

Definition at line 98 of file fixedSizePolymorphicHolder.h.

◆ Get() [2/2]

Base const * Get ( ) const
inline

Returns a Base pointer to the held instance.

Definition at line 93 of file fixedSizePolymorphicHolder.h.

◆ New()

void New ( Args &&...  args)
inline

Creates an instance.

Uses placement-new to create an object of type Derived into the local storage. Will fail to compile if Derived's size or alignment is incompatible with the storage.

Definition at line 59 of file fixedSizePolymorphicHolder.h.


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