Classes | Functions
SmartPtr

Smart pointers with value semantics supporting polymorphic deep copies. More...

Classes

struct  aurora::OperatorNewCopy< T >
 Cloner that invokes the copy constructor and new operator. More...
 
struct  aurora::VirtualClone< T >
 Cloner that invokes a member function clone(). More...
 
struct  aurora::OperatorDelete< T >
 Deleter that invokes the delete operator. More...
 
class  aurora::CopiedPtr< T >
 Copyable smart pointer template. More...
 

Functions

template<typename T , typename... Args>
std::unique_ptr< T > aurora::makeUnique (Args &&...args)
 Emplaces an object directly inside the unique pointer. More...
 
template<typename T >
void swap (CopiedPtr< T > &lhs, CopiedPtr< T > &rhs)
 Swaps the contents of two CopiedPtr instances.
 
template<typename T , typename... Args>
CopiedPtr< T > makeCopied (Args &&...args)
 Emplaces an object directly inside the copied pointer. More...
 

Detailed Description

Smart pointers with value semantics supporting polymorphic deep copies.

Function Documentation

template<typename T , typename... Args>
CopiedPtr< T > makeCopied ( Args &&...  args)
related

Emplaces an object directly inside the copied pointer.

Parameters
argsVariable argument list, the single arguments are forwarded to T's constructor. If your compiler does not support variadic templates, the number of arguments must be smaller than AURORA_PP_LIMIT.

This function has several advantages over the regular CopiedPtr(U*) constructor:

  • The new operator is encapsulated, making code exception-safe (in cases where multiple temporary smart pointers are constructed).
  • This function is considerably more efficient and requires less memory, because pointee and cloner/deleter can be stored together.
  • You avoid mentioning the pointee type twice.

Example:

auto ptr = aurora::makeCopied<MyClass>(arg1, arg2); // instead of
aurora::CopiedPtr<MyClass> ptr(new MyClass(arg1, arg2));
template<typename T , typename... Args>
std::unique_ptr<T> aurora::makeUnique ( Args &&...  args)

Emplaces an object directly inside the unique pointer.

Parameters
argsVariable argument list, the single arguments are forwarded to T's constructor. If your compiler does not support variadic templates, the number of arguments must be smaller than AURORA_PP_LIMIT.

Does the same as std::make_unique() in C++14. Example:

auto ptr = aurora::makeUnique<MyClass>(arg1, arg2); // instead of
std::unique_ptr<MyClass> ptr(new MyClass(arg1, arg2));