An implementation of smart pointers for C++. Features regular STL pointers as well as a custom IntrusivePtr
- Provides unique ownership semantics
- Non-copyable
- Accepts a generic
Deleterto support custom deallocation logic - The implementation employs empty base optimization to avoid storing empty
Deleterinstances without any state. This is achieved with a customCompressedPair. - Exactly pointer-sized when used with an empty deleter (including the default one)
- Supports ownership transfer via move semantics
- Template specialization for arrays that correctly handles construction/destruction
- Follows the
std::unique_ptrAPI
- Provides shared ownership semantics
- Allocates a control block separately by default
- An optimized
MakeSharedimplementation is provided. Stores the object and its reference count in a single contiguous allocation. - Always pointer-sized
- Follows the
std::shared_ptrAPI
- Weak reference to a
SharedPtr-managed object - Holds shared ownership of the control block
- Always pointer-sized
- Follows the
std::weak_ptrAPI
- Allows a class to construct
SharedPtrfromthisvia CRTP - Avoids double-freeing
this - Correctly handles creation of a new shared pointer and retrieval of existing one
- Lightweight alternative to
SharedPtrfor objects with internal refcount logic - Requires the type to implement a specific interface
- Supports complex object lifetimes
- A convenient CRTP refcount mixin is provided