From eb15e8a6b950b8f80784a15cbdcd9e4b020b31d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sun, 15 Mar 2015 19:03:50 +0800 Subject: [PATCH] shared_ptr --- TinySTL/Memory.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/TinySTL/Memory.h b/TinySTL/Memory.h index bba9941..3629b5f 100644 --- a/TinySTL/Memory.h +++ b/TinySTL/Memory.h @@ -1,8 +1,10 @@ #ifndef _MEMORY_H_ -#define _MEMORY_H +#define _MEMORY_H_ #include +#include "Detail\Ref.h" + namespace TinySTL{ template struct default_delete{ @@ -100,6 +102,24 @@ namespace TinySTL{ unique_ptr make_unique(Args&&... args){ return unique_ptr(new T(std::forward(args)...)); }; + + template + class shared_ptr{ + public: + typedef T element_type; + public: + explicit shared_ptr(T *p = nullptr) :ref_(new ref_t(p)){} + template + shared_ptr(T *p, D del) : ref_(new ref_t(p, del)){} + + element_type* get() const{ return ref_->get_data(); } + size_t use_count() const{ return ref_->count(); } + private: + template + using ref_t = Detail::ref_t < Type > ; + + ref_t *ref_; + }; } #endif \ No newline at end of file -- GitLab