Part of Project_zero.
A Dynamic-Link Library (DLL) implementing custom smart pointers that mirror the behaviour of their standard library counterparts. All classes are exported with __declspec(dllexport) / SMARTPTR_API so they can be consumed by any project that links the import library.
Auto_ptr<T>— ownership-transfer pointer (similar to the deprecatedstd::auto_ptr); includes avoidspecializationUnique_ptr<T>/Unique_ptr<T[]>— exclusive ownership; supports custom deleters via a template parameterShared_ptr<T>/Shared_ptr<T[]>— reference-counted shared ownership with a control blockWeak_ptr<T>/Weak_ptr<T[]>— non-owning observer of aShared_ptr; avoids circular reference leaks
Factory functions
make_unique<T>(...)— constructs aUnique_ptrin one allocationmake_shared<T>(...)— constructs aShared_ptrwith a single allocation (object + control block together)
Custom deleters built-in
Default_deleter<T>— callsdeleteArray_deleter<T>— callsdelete[]Noop_deleter<T>— does nothing (for stack/static objects)Custom_deleter<T>— wraps any callable
1. Include the header
#include "Smart_ptr.h"2. Link the import library
In Visual Studio:
- Linker → Input → Additional Dependencies → add
Smart_ptr.lib - Linker → General → Additional Library Directories → add the path to
x64/Release/
3. Place the DLL next to your executable
Important:
Smart_ptr.dllmust be in the same directory as your.exeat runtime, otherwise the application will fail to start with a "DLL not found" error.
Copy x64/Release/Smart_ptr.dll alongside your built executable, or add x64/Release/ to your system PATH.
#include "Smart_ptr.h"
#include <iostream>
struct MyObject {
int value;
MyObject(int v) : value(v) { std::cout << "Created " << v << "\n"; }
~MyObject() { std::cout << "Destroyed " << value << "\n"; }
};
int main() {
// Unique ownership
auto u = make_unique<MyObject>(10);
std::cout << u->value << "\n";
// Shared ownership
auto s1 = make_shared<MyObject>(20);
auto s2 = s1; // reference count = 2
std::cout << s1.use_count() << "\n"; // prints 2
// Weak observer
Weak_ptr<MyObject> w = s1;
if (auto locked = w.lock())
std::cout << "Still alive: " << locked->value << "\n";
// Array variant
auto arr = make_unique<int[]>(5);
arr[0] = 42;
}