A smart pointer class with reference counting and optional copy-on-write semantics. More...
#include <sharedptr.h>
Public Member Functions | |
| SharedPtr (const SharedPtr &sp) | |
| SharedPtr (SharedPtr &&sp) noexcept | |
| SharedPtr & | operator= (const SharedPtr &sp) |
| SharedPtr & | operator= (SharedPtr &&sp) noexcept |
| void | swap (SharedPtr &other) noexcept |
| void | clear () |
| void | detach () |
| bool | isNull () const |
| bool | isValid () const |
| operator bool () const | |
| bool | operator== (const SharedPtr &other) const |
| bool | operator!= (const SharedPtr &other) const |
| bool | operator== (std::nullptr_t) const |
| bool | operator!= (std::nullptr_t) const |
| int | referenceCount () const |
| const T * | ptr () const |
| T * | modify () |
| const T * | operator-> () const |
| const T & | operator* () const |
Static Public Member Functions | |
| template<typename... Args> | |
| static SharedPtr | create (Args &&... args) |
| static SharedPtr | takeOwnership (T *obj) |
Static Public Attributes | |
| static constexpr bool | isNative = IsSharedObject<T>::value |
| static constexpr bool | isCopyOnWrite = CopyOnWrite |
A smart pointer class with reference counting and optional copy-on-write semantics.
This class provides a reference-counted smart pointer for managing the lifetime of objects. It supports both native reference counting and proxy-based reference counting for objects that do not natively support it. Additionally, it offers (default enabled) copy-on-write semantics to optimize performance when multiple references exist.
Typical use case:
Thread Safety:
Limitations:
| T | The type of the object being managed. |
| CopyOnWrite | Whether copy-on-write semantics are enabled. |
| ST | The storage type for the managed object, for native objects this is the same as T. For non-native types, this is a proxy object. |