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 #ifndef _STL_UNINITIALIZED_H
00059 #define _STL_UNINITIALIZED_H 1
00060
00061 namespace std _GLIBCXX_VISIBILITY(default)
00062 {
00063 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00064
00065 template<bool _TrivialValueTypes>
00066 struct __uninitialized_copy
00067 {
00068 template<typename _InputIterator, typename _ForwardIterator>
00069 static _ForwardIterator
00070 __uninit_copy(_InputIterator __first, _InputIterator __last,
00071 _ForwardIterator __result)
00072 {
00073 _ForwardIterator __cur = __result;
00074 __try
00075 {
00076 for (; __first != __last; ++__first, ++__cur)
00077 std::_Construct(std::__addressof(*__cur), *__first);
00078 return __cur;
00079 }
00080 __catch(...)
00081 {
00082 std::_Destroy(__result, __cur);
00083 __throw_exception_again;
00084 }
00085 }
00086 };
00087
00088 template<>
00089 struct __uninitialized_copy<true>
00090 {
00091 template<typename _InputIterator, typename _ForwardIterator>
00092 static _ForwardIterator
00093 __uninit_copy(_InputIterator __first, _InputIterator __last,
00094 _ForwardIterator __result)
00095 { return std::copy(__first, __last, __result); }
00096 };
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 template<typename _InputIterator, typename _ForwardIterator>
00108 inline _ForwardIterator
00109 uninitialized_copy(_InputIterator __first, _InputIterator __last,
00110 _ForwardIterator __result)
00111 {
00112 typedef typename iterator_traits<_InputIterator>::value_type
00113 _ValueType1;
00114 typedef typename iterator_traits<_ForwardIterator>::value_type
00115 _ValueType2;
00116
00117 return std::__uninitialized_copy<(__is_trivial(_ValueType1)
00118 && __is_trivial(_ValueType2))>::
00119 __uninit_copy(__first, __last, __result);
00120 }
00121
00122
00123 template<bool _TrivialValueType>
00124 struct __uninitialized_fill
00125 {
00126 template<typename _ForwardIterator, typename _Tp>
00127 static void
00128 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
00129 const _Tp& __x)
00130 {
00131 _ForwardIterator __cur = __first;
00132 __try
00133 {
00134 for (; __cur != __last; ++__cur)
00135 std::_Construct(std::__addressof(*__cur), __x);
00136 }
00137 __catch(...)
00138 {
00139 std::_Destroy(__first, __cur);
00140 __throw_exception_again;
00141 }
00142 }
00143 };
00144
00145 template<>
00146 struct __uninitialized_fill<true>
00147 {
00148 template<typename _ForwardIterator, typename _Tp>
00149 static void
00150 __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
00151 const _Tp& __x)
00152 { std::fill(__first, __last, __x); }
00153 };
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 template<typename _ForwardIterator, typename _Tp>
00165 inline void
00166 uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last,
00167 const _Tp& __x)
00168 {
00169 typedef typename iterator_traits<_ForwardIterator>::value_type
00170 _ValueType;
00171
00172 std::__uninitialized_fill<__is_trivial(_ValueType)>::
00173 __uninit_fill(__first, __last, __x);
00174 }
00175
00176
00177 template<bool _TrivialValueType>
00178 struct __uninitialized_fill_n
00179 {
00180 template<typename _ForwardIterator, typename _Size, typename _Tp>
00181 static void
00182 __uninit_fill_n(_ForwardIterator __first, _Size __n,
00183 const _Tp& __x)
00184 {
00185 _ForwardIterator __cur = __first;
00186 __try
00187 {
00188 for (; __n > 0; --__n, ++__cur)
00189 std::_Construct(std::__addressof(*__cur), __x);
00190 }
00191 __catch(...)
00192 {
00193 std::_Destroy(__first, __cur);
00194 __throw_exception_again;
00195 }
00196 }
00197 };
00198
00199 template<>
00200 struct __uninitialized_fill_n<true>
00201 {
00202 template<typename _ForwardIterator, typename _Size, typename _Tp>
00203 static void
00204 __uninit_fill_n(_ForwardIterator __first, _Size __n,
00205 const _Tp& __x)
00206 { std::fill_n(__first, __n, __x); }
00207 };
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 template<typename _ForwardIterator, typename _Size, typename _Tp>
00219 inline void
00220 uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
00221 {
00222 typedef typename iterator_traits<_ForwardIterator>::value_type
00223 _ValueType;
00224
00225 std::__uninitialized_fill_n<__is_trivial(_ValueType)>::
00226 __uninit_fill_n(__first, __n, __x);
00227 }
00228
00229
00230
00231
00232
00233
00234
00235 template<typename _InputIterator, typename _ForwardIterator,
00236 typename _Allocator>
00237 _ForwardIterator
00238 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
00239 _ForwardIterator __result, _Allocator& __alloc)
00240 {
00241 _ForwardIterator __cur = __result;
00242 __try
00243 {
00244 for (; __first != __last; ++__first, ++__cur)
00245 __alloc.construct(std::__addressof(*__cur), *__first);
00246 return __cur;
00247 }
00248 __catch(...)
00249 {
00250 std::_Destroy(__result, __cur, __alloc);
00251 __throw_exception_again;
00252 }
00253 }
00254
00255 template<typename _InputIterator, typename _ForwardIterator, typename _Tp>
00256 inline _ForwardIterator
00257 __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
00258 _ForwardIterator __result, allocator<_Tp>&)
00259 { return std::uninitialized_copy(__first, __last, __result); }
00260
00261 template<typename _InputIterator, typename _ForwardIterator,
00262 typename _Allocator>
00263 inline _ForwardIterator
00264 __uninitialized_move_a(_InputIterator __first, _InputIterator __last,
00265 _ForwardIterator __result, _Allocator& __alloc)
00266 {
00267 return std::__uninitialized_copy_a(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
00268 _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
00269 __result, __alloc);
00270 }
00271
00272 template<typename _ForwardIterator, typename _Tp, typename _Allocator>
00273 void
00274 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
00275 const _Tp& __x, _Allocator& __alloc)
00276 {
00277 _ForwardIterator __cur = __first;
00278 __try
00279 {
00280 for (; __cur != __last; ++__cur)
00281 __alloc.construct(std::__addressof(*__cur), __x);
00282 }
00283 __catch(...)
00284 {
00285 std::_Destroy(__first, __cur, __alloc);
00286 __throw_exception_again;
00287 }
00288 }
00289
00290 template<typename _ForwardIterator, typename _Tp, typename _Tp2>
00291 inline void
00292 __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last,
00293 const _Tp& __x, allocator<_Tp2>&)
00294 { std::uninitialized_fill(__first, __last, __x); }
00295
00296 template<typename _ForwardIterator, typename _Size, typename _Tp,
00297 typename _Allocator>
00298 void
00299 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
00300 const _Tp& __x, _Allocator& __alloc)
00301 {
00302 _ForwardIterator __cur = __first;
00303 __try
00304 {
00305 for (; __n > 0; --__n, ++__cur)
00306 __alloc.construct(std::__addressof(*__cur), __x);
00307 }
00308 __catch(...)
00309 {
00310 std::_Destroy(__first, __cur, __alloc);
00311 __throw_exception_again;
00312 }
00313 }
00314
00315 template<typename _ForwardIterator, typename _Size, typename _Tp,
00316 typename _Tp2>
00317 inline void
00318 __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n,
00319 const _Tp& __x, allocator<_Tp2>&)
00320 { std::uninitialized_fill_n(__first, __n, __x); }
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 template<typename _InputIterator1, typename _InputIterator2,
00333 typename _ForwardIterator, typename _Allocator>
00334 inline _ForwardIterator
00335 __uninitialized_copy_move(_InputIterator1 __first1,
00336 _InputIterator1 __last1,
00337 _InputIterator2 __first2,
00338 _InputIterator2 __last2,
00339 _ForwardIterator __result,
00340 _Allocator& __alloc)
00341 {
00342 _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1,
00343 __result,
00344 __alloc);
00345 __try
00346 {
00347 return std::__uninitialized_move_a(__first2, __last2, __mid, __alloc);
00348 }
00349 __catch(...)
00350 {
00351 std::_Destroy(__result, __mid, __alloc);
00352 __throw_exception_again;
00353 }
00354 }
00355
00356
00357
00358
00359
00360 template<typename _InputIterator1, typename _InputIterator2,
00361 typename _ForwardIterator, typename _Allocator>
00362 inline _ForwardIterator
00363 __uninitialized_move_copy(_InputIterator1 __first1,
00364 _InputIterator1 __last1,
00365 _InputIterator2 __first2,
00366 _InputIterator2 __last2,
00367 _ForwardIterator __result,
00368 _Allocator& __alloc)
00369 {
00370 _ForwardIterator __mid = std::__uninitialized_move_a(__first1, __last1,
00371 __result,
00372 __alloc);
00373 __try
00374 {
00375 return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc);
00376 }
00377 __catch(...)
00378 {
00379 std::_Destroy(__result, __mid, __alloc);
00380 __throw_exception_again;
00381 }
00382 }
00383
00384
00385
00386
00387 template<typename _ForwardIterator, typename _Tp, typename _InputIterator,
00388 typename _Allocator>
00389 inline _ForwardIterator
00390 __uninitialized_fill_move(_ForwardIterator __result, _ForwardIterator __mid,
00391 const _Tp& __x, _InputIterator __first,
00392 _InputIterator __last, _Allocator& __alloc)
00393 {
00394 std::__uninitialized_fill_a(__result, __mid, __x, __alloc);
00395 __try
00396 {
00397 return std::__uninitialized_move_a(__first, __last, __mid, __alloc);
00398 }
00399 __catch(...)
00400 {
00401 std::_Destroy(__result, __mid, __alloc);
00402 __throw_exception_again;
00403 }
00404 }
00405
00406
00407
00408
00409 template<typename _InputIterator, typename _ForwardIterator, typename _Tp,
00410 typename _Allocator>
00411 inline void
00412 __uninitialized_move_fill(_InputIterator __first1, _InputIterator __last1,
00413 _ForwardIterator __first2,
00414 _ForwardIterator __last2, const _Tp& __x,
00415 _Allocator& __alloc)
00416 {
00417 _ForwardIterator __mid2 = std::__uninitialized_move_a(__first1, __last1,
00418 __first2,
00419 __alloc);
00420 __try
00421 {
00422 std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc);
00423 }
00424 __catch(...)
00425 {
00426 std::_Destroy(__first2, __mid2, __alloc);
00427 __throw_exception_again;
00428 }
00429 }
00430
00431 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00432
00433
00434
00435 template<bool _TrivialValueType>
00436 struct __uninitialized_default_1
00437 {
00438 template<typename _ForwardIterator>
00439 static void
00440 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
00441 {
00442 _ForwardIterator __cur = __first;
00443 __try
00444 {
00445 for (; __cur != __last; ++__cur)
00446 std::_Construct(std::__addressof(*__cur));
00447 }
00448 __catch(...)
00449 {
00450 std::_Destroy(__first, __cur);
00451 __throw_exception_again;
00452 }
00453 }
00454 };
00455
00456 template<>
00457 struct __uninitialized_default_1<true>
00458 {
00459 template<typename _ForwardIterator>
00460 static void
00461 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
00462 {
00463 typedef typename iterator_traits<_ForwardIterator>::value_type
00464 _ValueType;
00465
00466 std::fill(__first, __last, _ValueType());
00467 }
00468 };
00469
00470 template<bool _TrivialValueType>
00471 struct __uninitialized_default_n_1
00472 {
00473 template<typename _ForwardIterator, typename _Size>
00474 static void
00475 __uninit_default_n(_ForwardIterator __first, _Size __n)
00476 {
00477 _ForwardIterator __cur = __first;
00478 __try
00479 {
00480 for (; __n > 0; --__n, ++__cur)
00481 std::_Construct(std::__addressof(*__cur));
00482 }
00483 __catch(...)
00484 {
00485 std::_Destroy(__first, __cur);
00486 __throw_exception_again;
00487 }
00488 }
00489 };
00490
00491 template<>
00492 struct __uninitialized_default_n_1<true>
00493 {
00494 template<typename _ForwardIterator, typename _Size>
00495 static void
00496 __uninit_default_n(_ForwardIterator __first, _Size __n)
00497 {
00498 typedef typename iterator_traits<_ForwardIterator>::value_type
00499 _ValueType;
00500
00501 std::fill_n(__first, __n, _ValueType());
00502 }
00503 };
00504
00505
00506
00507
00508 template<typename _ForwardIterator>
00509 inline void
00510 __uninitialized_default(_ForwardIterator __first,
00511 _ForwardIterator __last)
00512 {
00513 typedef typename iterator_traits<_ForwardIterator>::value_type
00514 _ValueType;
00515
00516 std::__uninitialized_default_1<__is_trivial(_ValueType)>::
00517 __uninit_default(__first, __last);
00518 }
00519
00520
00521
00522 template<typename _ForwardIterator, typename _Size>
00523 inline void
00524 __uninitialized_default_n(_ForwardIterator __first, _Size __n)
00525 {
00526 typedef typename iterator_traits<_ForwardIterator>::value_type
00527 _ValueType;
00528
00529 std::__uninitialized_default_n_1<__is_trivial(_ValueType)>::
00530 __uninit_default_n(__first, __n);
00531 }
00532
00533
00534
00535
00536
00537 template<typename _ForwardIterator, typename _Allocator>
00538 void
00539 __uninitialized_default_a(_ForwardIterator __first,
00540 _ForwardIterator __last,
00541 _Allocator& __alloc)
00542 {
00543 _ForwardIterator __cur = __first;
00544 __try
00545 {
00546 for (; __cur != __last; ++__cur)
00547 __alloc.construct(std::__addressof(*__cur));
00548 }
00549 __catch(...)
00550 {
00551 std::_Destroy(__first, __cur, __alloc);
00552 __throw_exception_again;
00553 }
00554 }
00555
00556 template<typename _ForwardIterator, typename _Tp>
00557 inline void
00558 __uninitialized_default_a(_ForwardIterator __first,
00559 _ForwardIterator __last,
00560 allocator<_Tp>&)
00561 { std::__uninitialized_default(__first, __last); }
00562
00563
00564
00565
00566
00567 template<typename _ForwardIterator, typename _Size, typename _Allocator>
00568 void
00569 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
00570 _Allocator& __alloc)
00571 {
00572 _ForwardIterator __cur = __first;
00573 __try
00574 {
00575 for (; __n > 0; --__n, ++__cur)
00576 __alloc.construct(std::__addressof(*__cur));
00577 }
00578 __catch(...)
00579 {
00580 std::_Destroy(__first, __cur, __alloc);
00581 __throw_exception_again;
00582 }
00583 }
00584
00585 template<typename _ForwardIterator, typename _Size, typename _Tp>
00586 inline void
00587 __uninitialized_default_n_a(_ForwardIterator __first, _Size __n,
00588 allocator<_Tp>&)
00589 { std::__uninitialized_default_n(__first, __n); }
00590
00591
00592 template<typename _InputIterator, typename _Size,
00593 typename _ForwardIterator>
00594 _ForwardIterator
00595 __uninitialized_copy_n(_InputIterator __first, _Size __n,
00596 _ForwardIterator __result, input_iterator_tag)
00597 {
00598 _ForwardIterator __cur = __result;
00599 __try
00600 {
00601 for (; __n > 0; --__n, ++__first, ++__cur)
00602 std::_Construct(std::__addressof(*__cur), *__first);
00603 return __cur;
00604 }
00605 __catch(...)
00606 {
00607 std::_Destroy(__result, __cur);
00608 __throw_exception_again;
00609 }
00610 }
00611
00612 template<typename _RandomAccessIterator, typename _Size,
00613 typename _ForwardIterator>
00614 inline _ForwardIterator
00615 __uninitialized_copy_n(_RandomAccessIterator __first, _Size __n,
00616 _ForwardIterator __result,
00617 random_access_iterator_tag)
00618 { return std::uninitialized_copy(__first, __first + __n, __result); }
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629 template<typename _InputIterator, typename _Size, typename _ForwardIterator>
00630 inline _ForwardIterator
00631 uninitialized_copy_n(_InputIterator __first, _Size __n,
00632 _ForwardIterator __result)
00633 { return std::__uninitialized_copy_n(__first, __n, __result,
00634 std::__iterator_category(__first)); }
00635 #endif
00636
00637 _GLIBCXX_END_NAMESPACE_VERSION
00638 }
00639
00640 #endif