00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
#ifndef _STL_UNINITIALIZED_H
00062
#define _STL_UNINITIALIZED_H 1
00063
00064
#include <cstring>
00065
00066
namespace std
00067 {
00068
00069
template<
typename _InputIterator,
typename _ForwardIterator>
00070
inline _ForwardIterator
00071 __uninitialized_copy_aux(_InputIterator __first, _InputIterator __last,
00072 _ForwardIterator __result,
00073 __true_type)
00074 {
return std::copy(__first, __last, __result); }
00075
00076
template<
typename _InputIterator,
typename _ForwardIterator>
00077
inline _ForwardIterator
00078 __uninitialized_copy_aux(_InputIterator __first, _InputIterator __last,
00079 _ForwardIterator __result,
00080 __false_type)
00081 {
00082 _ForwardIterator __cur = __result;
00083
try
00084 {
00085
for (; __first != __last; ++__first, ++__cur)
00086 std::_Construct(&*__cur, *__first);
00087
return __cur;
00088 }
00089
catch(...)
00090 {
00091 std::_Destroy(__result, __cur);
00092 __throw_exception_again;
00093 }
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
template<
typename _InputIterator,
typename _ForwardIterator>
00106
inline _ForwardIterator
00107 uninitialized_copy(_InputIterator __first, _InputIterator __last,
00108 _ForwardIterator __result)
00109 {
00110
typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
00111
typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
00112
return std::__uninitialized_copy_aux(__first, __last, __result,
00113 _Is_POD());
00114 }
00115
00116
inline char*
00117
uninitialized_copy(
const char* __first,
const char* __last,
char* __result)
00118 {
00119 std::memmove(__result, __first, __last - __first);
00120
return __result + (__last - __first);
00121 }
00122
00123
inline wchar_t*
00124
uninitialized_copy(
const wchar_t* __first,
const wchar_t* __last,
00125
wchar_t* __result)
00126 {
00127 std::memmove(__result, __first,
sizeof(
wchar_t) * (__last - __first));
00128
return __result + (__last - __first);
00129 }
00130
00131
00132
00133
template<
typename _ForwardIterator,
typename _Tp>
00134
inline void
00135 __uninitialized_fill_aux(_ForwardIterator __first,
00136 _ForwardIterator __last,
00137
const _Tp& __x, __true_type)
00138 {
std::fill(__first, __last, __x); }
00139
00140
template<
typename _ForwardIterator,
typename _Tp>
00141
void
00142 __uninitialized_fill_aux(_ForwardIterator __first, _ForwardIterator __last,
00143
const _Tp& __x, __false_type)
00144 {
00145 _ForwardIterator __cur = __first;
00146
try
00147 {
00148
for (; __cur != __last; ++__cur)
00149 std::_Construct(&*__cur, __x);
00150 }
00151
catch(...)
00152 {
00153 std::_Destroy(__first, __cur);
00154 __throw_exception_again;
00155 }
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
template<
typename _ForwardIterator,
typename _Tp>
00168
inline void
00169 uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last,
00170
const _Tp& __x)
00171 {
00172
typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
00173
typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
00174 std::__uninitialized_fill_aux(__first, __last, __x, _Is_POD());
00175 }
00176
00177
00178
00179
template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
00180
inline void
00181 __uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n,
00182
const _Tp& __x, __true_type)
00183 {
std::fill_n(__first, __n, __x); }
00184
00185
template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
00186
void
00187 __uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n,
00188
const _Tp& __x, __false_type)
00189 {
00190 _ForwardIterator __cur = __first;
00191
try
00192 {
00193
for (; __n > 0; --__n, ++__cur)
00194 std::_Construct(&*__cur, __x);
00195 }
00196
catch(...)
00197 {
00198 std::_Destroy(__first, __cur);
00199 __throw_exception_again;
00200 }
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
template<
typename _ForwardIterator,
typename _Size,
typename _Tp>
00213
inline void
00214 uninitialized_fill_n(_ForwardIterator __first, _Size __n,
const _Tp& __x)
00215 {
00216
typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
00217
typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
00218 std::__uninitialized_fill_n_aux(__first, __n, __x, _Is_POD());
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
template<
typename _InputIterator,
typename _ForwardIterator,
00228
typename _Allocator>
00229 _ForwardIterator
00230 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
00231 _ForwardIterator __result,
00232 _Allocator __alloc)
00233 {
00234 _ForwardIterator __cur = __result;
00235
try
00236 {
00237
for (; __first != __last; ++__first, ++__cur)
00238 __alloc.construct(&*__cur, *__first);
00239
return __cur;
00240 }
00241
catch(...)
00242 {
00243 std::_Destroy(__result, __cur, __alloc);
00244 __throw_exception_again;
00245 }
00246 }
00247
00248
template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp>
00249
inline _ForwardIterator
00250 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
00251 _ForwardIterator __result,
00252 allocator<_Tp>)
00253 {
00254
return std::uninitialized_copy(__first, __last, __result);
00255 }
00256
00257
template<
typename _ForwardIterator,
typename _Tp,
typename _Allocator>
00258
void
00259 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
00260
const _Tp& __x, _Allocator __alloc)
00261 {
00262 _ForwardIterator __cur = __first;
00263
try
00264 {
00265
for (; __cur != __last; ++__cur)
00266 __alloc.construct(&*__cur, __x);
00267 }
00268
catch(...)
00269 {
00270 std::_Destroy(__first, __cur, __alloc);
00271 __throw_exception_again;
00272 }
00273 }
00274
00275
template<
typename _ForwardIterator,
typename _Tp,
typename _Tp2>
00276
inline void
00277 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
00278
const _Tp& __x, allocator<_Tp2>)
00279 {
00280
std::uninitialized_fill(__first, __last, __x);
00281 }
00282
00283
template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
00284
typename _Allocator>
00285
void
00286 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
00287
const _Tp& __x,
00288 _Allocator __alloc)
00289 {
00290 _ForwardIterator __cur = __first;
00291
try
00292 {
00293
for (; __n > 0; --__n, ++__cur)
00294 __alloc.construct(&*__cur, __x);
00295 }
00296
catch(...)
00297 {
00298 std::_Destroy(__first, __cur, __alloc);
00299 __throw_exception_again;
00300 }
00301 }
00302
00303
template<
typename _ForwardIterator,
typename _Size,
typename _Tp,
00304
typename _Tp2>
00305
void
00306 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
00307
const _Tp& __x,
00308 allocator<_Tp2>)
00309 {
00310
std::uninitialized_fill_n(__first, __n, __x);
00311 }
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
template<
typename _InputIterator1,
typename _InputIterator2,
00324
typename _ForwardIterator,
typename _Allocator>
00325
inline _ForwardIterator
00326 __uninitialized_copy_copy(_InputIterator1 __first1,
00327 _InputIterator1 __last1,
00328 _InputIterator2 __first2,
00329 _InputIterator2 __last2,
00330 _ForwardIterator __result,
00331 _Allocator __alloc)
00332 {
00333 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
00334 __result,
00335 __alloc);
00336
try
00337 {
00338
return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
00339 }
00340
catch(...)
00341 {
00342 std::_Destroy(__result, __mid, __alloc);
00343 __throw_exception_again;
00344 }
00345 }
00346
00347
00348
00349
00350
template<
typename _ForwardIterator,
typename _Tp,
typename _InputIterator,
00351
typename _Allocator>
00352
inline _ForwardIterator
00353 __uninitialized_fill_copy(_ForwardIterator __result, _ForwardIterator __mid,
00354
const _Tp& __x, _InputIterator __first,
00355 _InputIterator __last,
00356 _Allocator __alloc)
00357 {
00358 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
00359
try
00360 {
00361
return std::__uninitialized_copy_a(__first, __last, __mid, __alloc);
00362 }
00363
catch(...)
00364 {
00365 std::_Destroy(__result, __mid, __alloc);
00366 __throw_exception_again;
00367 }
00368 }
00369
00370
00371
00372
00373
template<
typename _InputIterator,
typename _ForwardIterator,
typename _Tp,
00374
typename _Allocator>
00375
inline void
00376 __uninitialized_copy_fill(_InputIterator __first1, _InputIterator __last1,
00377 _ForwardIterator __first2,
00378 _ForwardIterator __last2,
const _Tp& __x,
00379 _Allocator __alloc)
00380 {
00381 _ForwardIterator __mid2 = std::__uninitialized_copy_a(__first1, __last1,
00382 __first2,
00383 __alloc);
00384
try
00385 {
00386 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
00387 }
00388
catch(...)
00389 {
00390 std::_Destroy(__first2, __mid2, __alloc);
00391 __throw_exception_again;
00392 }
00393 }
00394
00395 }
00396
00397
#endif