提交 eb15e8a6 编写于 作者: 邹晓航

shared_ptr

上级 c5a3ab8a
#ifndef _MEMORY_H_
#define _MEMORY_H
#define _MEMORY_H_
#include <utility>
#include "Detail\Ref.h"
namespace TinySTL{
template<class T>
struct default_delete{
......@@ -100,6 +102,24 @@ namespace TinySTL{
unique_ptr<T> make_unique(Args&&... args){
return unique_ptr<T>(new T(std::forward<Args>(args)...));
};
template<class T>
class shared_ptr{
public:
typedef T element_type;
public:
explicit shared_ptr(T *p = nullptr) :ref_(new ref_t<T>(p)){}
template<class D>
shared_ptr(T *p, D del) : ref_(new ref_t<T>(p, del)){}
element_type* get() const{ return ref_->get_data(); }
size_t use_count() const{ return ref_->count(); }
private:
template<class Type>
using ref_t = Detail::ref_t < Type > ;
ref_t<T> *ref_;
};
}
#endif
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册