-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathts_uninitialized.hpp
More file actions
161 lines (150 loc) · 3.56 KB
/
ts_uninitialized.hpp
File metadata and controls
161 lines (150 loc) · 3.56 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef TS_UNINITIALIZED_HPP
#define TS_UNINITIALIZED_HPP
#include "ts_alloc.hpp"
#include <cstddef>
namespace TS
{
// uninitialized_copy
template <typename InputIter, typename ForwardIter>
inline ForwardIter uninitialized_copy(InputIter first, InputIter last, ForwardIter result)
{
ForwardIter cur = result;
try
{
for (; first != last; ++first, ++cur)
{
construct(&*cur, *first);
}
}
catch (...)
{
for (ForwardIter it = result; it != cur; ++it)
{
destroy(&*it);
}
throw;
}
return cur;
}
template <typename InputIter, typename Size, typename ForwardIter>
inline ForwardIter uninitialized_copy_n(InputIter first, Size count, ForwardIter result)
{
ForwardIter cur = result;
try
{
for (; count > 0; --count, ++first, ++cur)
{
construct(&*cur, *first);
}
}
catch (...)
{
for (ForwardIter it = result; it != cur; ++it)
{
destroy(&*it);
}
throw;
}
return cur;
}
template <typename InputIter, typename ForwardIter>
inline ForwardIter uninitialized_copy_backward(InputIter first, InputIter last, ForwardIter result)
{
std::ptrdiff_t count = last - first;
--last;
try
{
for (ForwardIter cur = result + count - 1; cur != result - 1; --cur, --last)
{
construct(&*cur, *last);
}
}
catch (...)
{
ForwardIter result_last = result + count;
for (ForwardIter it = result; it != result_last; ++it)
{
destroy(&*it);
}
throw;
}
return result + count;
}
template <typename InputIter, typename Size, typename ForwardIter>
inline ForwardIter uninitialized_copy_backward_n(InputIter first, Size count, ForwardIter result)
{
InputIter last = first + count - 1;
try
{
for (ForwardIter cur = result + count - 1; cur != result - 1; --cur, --last)
{
construct(&*cur, *last);
}
}
catch (...)
{
ForwardIter result_last = result + count;
for (ForwardIter it = result; it != result_last; ++it)
{
detroy(&*it);
}
throw;
}
return result + count;
}
// uninitialized_fill
template <typename ForwardIter, typename T>
inline void uninitialized_fill(ForwardIter first, ForwardIter last, const T &val)
{
try
{
for (ForwardIter cur = first; cur != last; ++cur)
{
construct(&*cur, val);
}
}
catch (...)
{
for (ForwardIter it = first; it != last; ++it)
{
detroy(&*it);
}
throw;
}
}
template <typename ForwardIter, typename Size, typename T>
inline void uninitialized_fill_n(ForwardIter first, Size count, const T &val)
{
ForwardIter last = first + count;
try
{
for (ForwardIter cur = first; cur != last; ++cur)
{
construct(&*cur, val);
}
}
catch (...)
{
for (ForwardIter it = first; it != last; ++it)
{
destroy(&*it);
}
}
}
// template <typename ForwardIter> inline void uninitialized_break(ForwardIter first, ForwardIter last) noexcept
// {
// for (; first != last; ++first)
// {
// destroy(&*first);
// }
// }
// template <typename ForwardIter, typename Size> inline void uninitialized_break_n(ForwardIter first, Size count)
// noexcept
// {
// for (ForwardIter last = first + count; first != last; ++first)
// {
// destroy(&*first);
// }
// }
} // namespace TS
#endif