shared_ptr

This commit is contained in:
邹晓航
2015-03-15 19:03:50 +08:00
parent c5a3ab8aad
commit eb15e8a6b9

View File

@@ -1,8 +1,10 @@
#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