Classes | Functions
utl::ShadowPtrMeta Namespace Reference

Classes

struct  BoolSwitch
 
struct  BoolSwitch< true, T >
 
struct  False
 
struct  HasClone
 
struct  True
 

Functions

template<typename T >
T * Clone (const T &src)
 Clone a given object. More...
 
template<typename T >
T * CloneOne (const T &src)
 
template<typename T >
True MatchCloneTag (typename T::IsClonableTag *const)
 
template<typename T >
False MatchCloneTag (...)
 

Detailed Description

DV: For some classes (Type) that inherit from an pure abstract base class we can not call a (non-existing) copy constructor, i.e. we can not use new Type(t). The utl::CopyOrClone class does some meta-programming magic and uses copy constructor for normal objects and switches to a virtual copy constructor Clone() static method when it exists.

Function Documentation

template<typename T >
T* utl::ShadowPtrMeta::Clone ( const T &  src)

Clone a given object.

Parameters
srcObject to be cloned
Returns
Pointer to cloned object

This function exists as a customization point for the ShadowPtr template for classes which need a special cloning mechanism. If a class c is accompanied by a function c* Clone(const c& src) in the same namespace, it will get used instead of the this templated function due to Koenig lookup.

Note
This mechanism can be used to introduce an indirection for cloning. Normally, the the compiler has to see the full definition of a class in order to be able to instantiate the Clone template function. If an overloaded function gets called instead, the instantiation does not take place. The class specific Clone function can be declared in the header and defined with the rest of the class. This re-enables the use of forward declarations with shadow pointers, at the price of providing the class specific Clone.

Definition at line 69 of file ShadowPtr.h.

Referenced by CloneOne().

template<typename T >
T* utl::ShadowPtrMeta::CloneOne ( const T &  src)

Definition at line 73 of file ShadowPtr.h.

References Clone().

template<typename T >
True utl::ShadowPtrMeta::MatchCloneTag ( typename T::IsClonableTag *  const)
template<typename T >
False utl::ShadowPtrMeta::MatchCloneTag (   ...)

, generated on Tue Sep 26 2023.