shared_ptr
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
#ifndef _MEMORY_H_
|
#ifndef _MEMORY_H_
|
||||||
#define _MEMORY_H
|
#define _MEMORY_H_
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "Detail\Ref.h"
|
||||||
|
|
||||||
namespace TinySTL{
|
namespace TinySTL{
|
||||||
template<class T>
|
template<class T>
|
||||||
struct default_delete{
|
struct default_delete{
|
||||||
@@ -100,6 +102,24 @@ namespace TinySTL{
|
|||||||
unique_ptr<T> make_unique(Args&&... args){
|
unique_ptr<T> make_unique(Args&&... args){
|
||||||
return unique_ptr<T>(new T(std::forward<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
|
#endif
|
||||||
Reference in New Issue
Block a user