From dfe5081a998d79426f2861fcce69e6a2d2fa151b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Wed, 17 Sep 2014 09:20:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E5=92=8C=E9=94=80=E6=AF=81=E5=AF=B9=E8=B1=A1=E7=9A=84=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Construct.h | 38 +++++++++++++++++++++++++++++++++ TinySTL/TinySTL.vcxproj | 1 + TinySTL/TinySTL.vcxproj.filters | 3 +++ TinySTL/main.cpp | 2 ++ 4 files changed, 44 insertions(+) create mode 100644 TinySTL/Construct.h diff --git a/TinySTL/Construct.h b/TinySTL/Construct.h new file mode 100644 index 0000000..2e487f7 --- /dev/null +++ b/TinySTL/Construct.h @@ -0,0 +1,38 @@ +#ifndef _CONSTRUCT_H_ +#define _CONSTRUCT_H_ + +#include + +#include "TypeTraits.h" + +namespace TinySTL{ + + template + inline void construct(T1 *ptr1, const T2& value){ + new(ptr1) T1(value); + } + + template + inline void destroy(T *ptr){ + ptr->~T(); + } + + template + inline void _destroy(ForwardIterator first, ForwardIterator last, _true_type){} + + template + inline void _destroy(ForwardIterator first, ForwardIterator last, _false_type){ + for (; , first != last; ++first){ + destroy(&*first); + } + } + + template + inline void destroy(ForwardIterator first, ForwardIterator last){ + typedef typename _type_traits::is_POD_type is_POD_type; + _destroy(first, last, is_POD_type); + } + +} + +#endif \ No newline at end of file diff --git a/TinySTL/TinySTL.vcxproj b/TinySTL/TinySTL.vcxproj index d5e4188..1ef643d 100644 --- a/TinySTL/TinySTL.vcxproj +++ b/TinySTL/TinySTL.vcxproj @@ -79,6 +79,7 @@ + diff --git a/TinySTL/TinySTL.vcxproj.filters b/TinySTL/TinySTL.vcxproj.filters index cf09af5..f82fd29 100644 --- a/TinySTL/TinySTL.vcxproj.filters +++ b/TinySTL/TinySTL.vcxproj.filters @@ -23,5 +23,8 @@ 头文件 + + 头文件 + \ No newline at end of file diff --git a/TinySTL/main.cpp b/TinySTL/main.cpp index aafe121..55e903a 100644 --- a/TinySTL/main.cpp +++ b/TinySTL/main.cpp @@ -1,5 +1,7 @@ #include +#include "Construct.h" + using namespace std; int main(){