/
Construct.h
53 lines (38 loc) · 1.2 KB
/
Construct.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*************************************************************************
> File Name: Construct.h
> Author: hqwu
> Mail: wfq703@163.com
> Created Time: 2016年09月11日 星期日 10时37分53秒
************************************************************************/
#ifndef __CONSTRUCT_H
#define __CONSTRUCT_H
#include <new>
#include "Iterator.h"
#include "TypeTraits.h"
namespace tinySTL{
template<class T1,class T2>
inline void construct(T1 *p,T2 &value){
new (p) T1(value);
}
template<class T>
inline void destroy(T *p){
p->~T();
}
template<class ForwardIterator>
inline void __destroy_aux(ForwardIterator first,ForwardIterator last,struct __true_type){}
inline void __destroy_aux(ForwardIterator first,ForwardIterator last,struct __false_type){
for(;first!=last;++first){
destroy(&(*first));
}
}
template<class ForwardIterator,class T>
inline void __destroy(ForwardIterator first,ForwardIterator last,T*){
typedef typename type_traits<T>::is_POD_type is_POD_type;
__destroy_aux(first,last,is_POD_type());
}
template<class ForwardIterator>
inline void destroy(ForwardIterator first,ForwardIterator last){
__destroy(first,last,value_type(first));
}
}
#endif