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(){