Skip to content

yakuri354/smartptrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ smart pointer library

An implementation of smart pointers for C++. Features regular STL pointers as well as a custom IntrusivePtr

UniquePtr

  • Provides unique ownership semantics
  • Non-copyable
  • Accepts a generic Deleter to support custom deallocation logic
  • The implementation employs empty base optimization to avoid storing empty Deleter instances without any state. This is achieved with a custom CompressedPair.
  • 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_ptr API

SharedPtr

  • Provides shared ownership semantics
  • Allocates a control block separately by default
  • An optimized MakeShared implementation is provided. Stores the object and its reference count in a single contiguous allocation.
  • Always pointer-sized
  • Follows the std::shared_ptr API

WeakPtr

  • Weak reference to a SharedPtr-managed object
  • Holds shared ownership of the control block
  • Always pointer-sized
  • Follows the std::weak_ptr API

SharedFromThis

  • Allows a class to construct SharedPtr from this via CRTP
  • Avoids double-freeing this
  • Correctly handles creation of a new shared pointer and retrieval of existing one

IntrusivePtr

  • Lightweight alternative to SharedPtr for objects with internal refcount logic
  • Requires the type to implement a specific interface
  • Supports complex object lifetimes
  • A convenient CRTP refcount mixin is provided

About

C++ Smart Pointer Library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors