diff --git a/TinySTL/Detail/Ref.h b/TinySTL/Detail/Ref.h new file mode 100644 index 0000000..9f22598 --- /dev/null +++ b/TinySTL/Detail/Ref.h @@ -0,0 +1,42 @@ +#ifndef _REF_H_ +#define _REF_H_ + +#include + +namespace TinySTL{ + namespace Detail{ + template + struct ref_t{ + std::atomic ncount_; + T *data_; + + explicit ref_t(size_t n = 0, T *p = nullptr) :ncount_(n), data_(p){} + ref_t(const ref_t&) = default; + ref_t& operator = (const ref_t&) = default; + + size_t count()const{ return ncount_.load(); } + T *get_data()const{ return data_; } + + ref_t& operator ++(){ + ++ncount_; + return *this; + } + ref_t operator ++(int){ + auto t = *this; + ++*this; + return t; + } + ref_t& operator --(){ + --ncount_; + return *this; + } + ref_t operator --(int){ + auto t = *this; + --*this; + return t; + } + }; + } +} + +#endif \ No newline at end of file diff --git a/TinySTL/TinySTL.vcxproj b/TinySTL/TinySTL.vcxproj index 5bebb18..8ed7924 100644 --- a/TinySTL/TinySTL.vcxproj +++ b/TinySTL/TinySTL.vcxproj @@ -121,6 +121,7 @@ + diff --git a/TinySTL/TinySTL.vcxproj.filters b/TinySTL/TinySTL.vcxproj.filters index 88f8c9e..a452549 100644 --- a/TinySTL/TinySTL.vcxproj.filters +++ b/TinySTL/TinySTL.vcxproj.filters @@ -263,6 +263,9 @@ Test + + Detail +