Copyable smart pointer template. More...
Public Member Functions | |
CopiedPtr () | |
Default constructor. More... | |
CopiedPtr (std::nullptr_t) | |
Construct from nullptr. More... | |
template<typename U > | |
CopiedPtr (U *pointer) | |
Construct from raw pointer. More... | |
template<typename U , typename C > | |
CopiedPtr (U *pointer, C cloner) | |
Construct from raw pointer with cloner. More... | |
template<typename U , typename C , typename D > | |
CopiedPtr (U *pointer, C cloner, D deleter) | |
Construct from raw pointer with cloner and deleter. More... | |
CopiedPtr (const CopiedPtr &origin) | |
Copy constructor. More... | |
template<typename U > | |
CopiedPtr (const CopiedPtr< U > &origin) | |
Construct from different CopiedPtr. More... | |
CopiedPtr (CopiedPtr &&source) | |
Move constructor. More... | |
template<typename U > | |
CopiedPtr (CopiedPtr< U > &&source) | |
Move from different CopiedPtr. More... | |
CopiedPtr & | operator= (const CopiedPtr &origin) |
Copy assignment operator. More... | |
template<typename U > | |
CopiedPtr & | operator= (const CopiedPtr< U > &origin) |
Copy-assign from different CopiedPtr. More... | |
CopiedPtr & | operator= (CopiedPtr &&source) |
Move assignment operator. More... | |
template<typename U > | |
CopiedPtr & | operator= (CopiedPtr< U > &&source) |
Move-assign from different CopiedPtr. More... | |
~CopiedPtr () | |
Destructor. More... | |
void | swap (CopiedPtr &other) |
Exchanges the values of *this and other . | |
T & | operator* () const |
Dereferences the pointer. | |
T * | operator-> () const |
Dereferences the pointer for member access. | |
operator SafeBool () const | |
Checks if the smart pointer is not nullptr. More... | |
T * | get () const |
Permits access to the internal pointer. Designed for rare use. More... | |
void | reset () |
Reset to null pointer. More... | |
template<typename U > | |
void | reset (U *pointer) |
Reset to raw pointer. More... | |
template<typename U , typename C > | |
void | reset (U *pointer, C cloner) |
Reset to raw pointer with cloner. More... | |
template<typename U , typename C , typename D > | |
void | reset (U *pointer, C cloner, D deleter) |
Reset to raw pointer with cloner and deleter. More... | |
Related Functions | |
(Note that these are not member functions.) | |
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... | |
Copyable smart pointer template.
T | Type of the stored pointee object. Can be void. |
This class supports automatic destruction and copying. It has full value semantics, i.e. the stored object is destroyed in the smart pointer's destructor and copied in the smart pointer's copy constructor. The concept of custom cloners and deleters allows you to specify the way how destructions and copies are performed.
This smart pointer is always unique, no two CopiedPtr instances share the same object.
Every operation provides at least the strong exception guarantee: When copies of the pointee object throw an exception, the smart pointer will remain in a valid (uncommitted) state and no memory will be leaked. Move construction and move assignment from the same CopiedPtr<T> type additionally offer the nothrow guarantee; they involve neither copies nor moves of the pointee object. Operations on empty smart pointers (such as default constructor, copies/moves from null pointers) also provide the nothrow guarantee; they never involve any dynamic allocation.
aurora::CopiedPtr< T >::CopiedPtr | ( | ) |
Default constructor.
Initializes the smart pointer with a null pointer.
aurora::CopiedPtr< T >::CopiedPtr | ( | std::nullptr_t | ) |
Construct from nullptr.
Allows conversions from the nullptr
literal to a CopiedPtr.
|
explicit |
Construct from raw pointer.
pointer | Initial pointer value, can be nullptr. Must be convertible to T*. |
aurora::CopiedPtr< T >::CopiedPtr | ( | U * | pointer, |
C | cloner | ||
) |
Construct from raw pointer with cloner.
pointer | Initial pointer value, can be nullptr. Must be convertible to T*. |
cloner | Callable with signature T*(const T*) that is invoked during CopiedPtr copies. Must return a pointer to a copy of the argument. |
Uses OperatorDelete<U> as deleter. Make sure your cloner returns an object allocated with new.
aurora::CopiedPtr< T >::CopiedPtr | ( | U * | pointer, |
C | cloner, | ||
D | deleter | ||
) |
Construct from raw pointer with cloner and deleter.
pointer | Initial pointer value, can be nullptr. Must be convertible to T*. |
cloner | Callable with signature T*(const T*) that is invoked during CopiedPtr copies. Must return a pointer to a copy of the argument. |
deleter | Callable with signature void(T*) that is invoked during CopiedPtr destruction. |
aurora::CopiedPtr< T >::CopiedPtr | ( | const CopiedPtr< T > & | origin | ) |
Copy constructor.
origin | Original smart pointer |
If the origin's pointer is nullptr
, this pointer will also be nullptr
. Otherwise, this instance will hold the pointer returned by the cloner.
aurora::CopiedPtr< T >::CopiedPtr | ( | const CopiedPtr< U > & | origin | ) |
Construct from different CopiedPtr.
origin | Original smart pointer, where U* convertible to T*. Can refer to a derived object. |
If the origin's pointer is nullptr
, this pointer will also be nullptr
. Otherwise, this instance will hold the pointer returned by the cloner.
aurora::CopiedPtr< T >::CopiedPtr | ( | CopiedPtr< T > && | source | ) |
Move constructor.
source | RValue reference to object of which the ownership is taken. |
aurora::CopiedPtr< T >::CopiedPtr | ( | CopiedPtr< U > && | source | ) |
Move from different CopiedPtr.
source | RValue reference to object of which the ownership is taken. |
In contrast to the move constructor, this constructor does not offer the nothrow guarantee. Only strong exception guarantee is provided (because of an internal allocation; the pointee object is not copied).
aurora::CopiedPtr< T >::~CopiedPtr | ( | ) |
Destructor.
Invokes the deleter with the stored pointer as argument.
T* aurora::CopiedPtr< T >::get | ( | ) | const |
Permits access to the internal pointer. Designed for rare use.
aurora::CopiedPtr< T >::operator SafeBool | ( | ) | const |
Checks if the smart pointer is not nullptr.
Allows expressions of the form if (ptr)
or if (!ptr)
.
CopiedPtr& aurora::CopiedPtr< T >::operator= | ( | const CopiedPtr< T > & | origin | ) |
Copy assignment operator.
origin | Original smart pointer |
Can imply a copy and a destruction, invoking origin's cloner and this deleter.
CopiedPtr& aurora::CopiedPtr< T >::operator= | ( | const CopiedPtr< U > & | origin | ) |
Copy-assign from different CopiedPtr.
origin | Original smart pointer, where U* convertible to T*. Can refer to a derived object. |
Can imply a copy and a destruction, invoking origin's cloner and this deleter.
CopiedPtr& aurora::CopiedPtr< T >::operator= | ( | CopiedPtr< T > && | source | ) |
Move assignment operator.
source | RValue reference to object of which the ownership is taken. |
CopiedPtr& aurora::CopiedPtr< T >::operator= | ( | CopiedPtr< U > && | source | ) |
Move-assign from different CopiedPtr.
source | RValue reference to object of which the ownership is taken. |
In contrast to the move assignment operator, this assignment operator does not offer the nothrow guarantee. Only strong exception guarantee is provided (because of an internal allocation; the pointee object is not copied).
void aurora::CopiedPtr< T >::reset | ( | ) |
Reset to null pointer.
If this instance currently holds a pointer, the old deleter is invoked.
Reset to raw pointer.
pointer | Initial pointer value, can be nullptr. Must be convertible to T*. |
If this instance currently holds a pointer, the old deleter is invoked.
void aurora::CopiedPtr< T >::reset | ( | U * | pointer, |
C | cloner | ||
) |
Reset to raw pointer with cloner.
pointer | Initial pointer value, can be nullptr. Must be convertible to T*. |
cloner | Callable with signature T*(const T*) that is invoked during CopiedPtr copies. Must return a pointer to a copy of the argument. |
If this instance currently holds a pointer, the old deleter is invoked.
Uses OperatorDelete<U> as deleter. Make sure your cloner returns an object allocated with new.
void aurora::CopiedPtr< T >::reset | ( | U * | pointer, |
C | cloner, | ||
D | deleter | ||
) |
Reset to raw pointer with cloner and deleter.
pointer | Initial pointer value, can be nullptr. Must be convertible to T*. |
cloner | Callable with signature T*(const T*) that is invoked during CopiedPtr copies. Must return a pointer to a copy of the argument. |
deleter | Callable with signature void(T*) that is invoked during CopiedPtr destruction. |
If this instance currently holds a pointer, the old deleter is invoked.