-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconstruct.h
executable file
·54 lines (45 loc) · 1.55 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
54
// The core library - copyright GarageGames. The core library is released under the MIT Open Source software license. See /license.txt in this distribution for specific license terms.
template<typename type> inline type* construct(type* ptr)
{
return new((void*)ptr) type;
}
template<typename type> inline type* construct(type* ptr,const type& a)
{
return new((void*)ptr) type(a);
}
template<typename type> inline void destroy(type* ptr)
{
ptr->~type();
}
namespace internal {
template <class type> inline void construct_aux(type* ptr, type* end, true_type) {}
template <class type> inline void construct_aux(type* ptr, type* end, false_type)
{
while (ptr != end)
construct(ptr++);
}
} // Private
template<typename type> inline void construct(type* ptr,type* end)
{
typename bool_type<has_trivial_constructor<type>::is_true>::value_type is_trivial;
internal::construct_aux(ptr,end,is_trivial);
}
template<typename type> inline void construct(type* ptr,type* end,const type& x)
{
while (ptr != end)
construct(ptr++,x);
}
//-----------------------------------------------------------------------------
namespace internal {
template <class type> inline void destroy_aux(type* /*ptr*/, type* /*end*/, true_type) {}
template <class type> inline void destroy_aux(type* ptr, type* end, false_type)
{
while (ptr != end)
(ptr++)->~type();
}
} // Private
template<typename type> inline void destroy(type* ptr,type* end)
{
typename bool_type<has_trivial_destructor<type>::is_true>::value_type is_trivial;
internal::destroy_aux(ptr,end,is_trivial);
}