This is my own implementation of a template-based std::shared_ptr, without using std.
- Valgrind: No memory leaks.
HEAP SUMMARY:
in use at exit: 0 bytes in 0 blocks
heap usage: 20,311 allocs, 20,311 frees, 767,643 bytes allocated
All heap blocks were freed - no leaks are possible
For lists of detected and suppressed errors, rerun with: -s
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)- Google Test: The entire basic interface is covered with unit tests.
TEST(MyShared, default_constructor) {
SharedPtr<int> ptr;
ASSERT_THROW(*ptr, std::logic_error);
}SharedPtr()- default constructorSharedPtr(const T& resource)- constructor with objectSharedPtr(const SharedPtr& other)- copy constructor~SharedPtr()- destructor, delete resourceSharedPtr<T>& operator=(const SharedPtr<T>& other);- copy assigmentT& operator*()- return valid resourceT* get()- get resource addresssize_t use_refs()- get refs count
Move constructor is not implemented, and its explicit deletion is not possible.
SharedPtr<int> ptr(1);
std::cout << *ptr << '\n; // Output: 1;To build and run the project, follow these steps:
-
Requirements::
- VS Code
- CMake (last stable release)
- Git
-
Clone the Repository:
-
Open folder with VSCode and start build
-
In build folder
./shared_ptr