-
Notifications
You must be signed in to change notification settings - Fork 0
/
ml_construct.h
71 lines (52 loc) · 1.4 KB
/
ml_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* @file ml_construct.h
* @brief
* @author malin malinbupt@gmail.com
* @date 2015年04月02日 星期四 11时23分41秒
* @version
* @note
*/
#ifndef __ML_INTERNAL_CONSTRUCT_H
#define __ML_INTERNAL_CONSTRUCT_H
#include "ml_config.h"
#include "type_traits.h"
#include "ml_iterator_base.h"
#include <new>
__ML_BEGIN_NAMESPACE
template<typename T1, typename T2>
inline void construct(T1 *p, const T2 &val)
{
new(p) T1(val);
}
template<typename T>
inline void destroy(T *p)
{
p->~T();
}
template<typename ForwardIterator>
inline void __destroy_aux(ForwardIterator &first, ForwardIterator &last, __false_type)
{
while (first != last)
{
destroy(&*first); ++first;
}
}
template<typename ForwardIterator>
inline void __destroy_aux(ForwardIterator &first, ForwardIterator &last, __true_type) {}
template<typename ForwardIterator, typename T>
inline void __destroy(ForwardIterator &first, ForwardIterator &last, T*)
{
__destroy_aux(first, last, typename __type_traits<T>::has_trivial_destructor());
}
template<typename ForwardIterator>
inline void destroy(ForwardIterator first, ForwardIterator last)
{
__destroy(first, last, value_type(first));
}
inline void destroy(char*, char*) {}
inline void destroy(int*, int*) {}
inline void destroy(long*, long*) {}
inline void destroy(float*, float*) {}
inline void destroy(double*, double*) {}
__ML_END_NAMESPACE
#endif // __ML_INTERNAL_CONSTRUCT_H