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 #ifndef _CPP_BITS_STL_UNINITIALIZED_H
00061 #define _CPP_BITS_STL_UNINITIALIZED_H 1
00062
00063 #include <bits/std_cstring.h>
00064
00065 namespace std
00066 {
00067
00068
00069
00070
00071
00072 template <class _InputIter, class _ForwardIter>
00073 inline _ForwardIter
00074 __uninitialized_copy_aux(_InputIter __first, _InputIter __last,
00075 _ForwardIter __result,
00076 __true_type)
00077 {
00078 return copy(__first, __last, __result);
00079 }
00080
00081 template <class _InputIter, class _ForwardIter>
00082 _ForwardIter
00083 __uninitialized_copy_aux(_InputIter __first, _InputIter __last,
00084 _ForwardIter __result,
00085 __false_type)
00086 {
00087 _ForwardIter __cur = __result;
00088 __STL_TRY {
00089 for ( ; __first != __last; ++__first, ++__cur)
00090 _Construct(&*__cur, *__first);
00091 return __cur;
00092 }
00093 __STL_UNWIND(_Destroy(__result, __cur));
00094 }
00095
00096
00097 template <class _InputIter, class _ForwardIter, class _Tp>
00098 inline _ForwardIter
00099 __uninitialized_copy(_InputIter __first, _InputIter __last,
00100 _ForwardIter __result, _Tp*)
00101 {
00102 typedef typename __type_traits<_Tp>::is_POD_type _Is_POD;
00103 return __uninitialized_copy_aux(__first, __last, __result, _Is_POD());
00104 }
00105
00106 template <class _InputIter, class _ForwardIter>
00107 inline _ForwardIter
00108 uninitialized_copy(_InputIter __first, _InputIter __last,
00109 _ForwardIter __result)
00110 {
00111 return __uninitialized_copy(__first, __last, __result,
00112 __value_type(__result));
00113 }
00114
00115 inline char* uninitialized_copy(const char* __first, const char* __last,
00116 char* __result) {
00117 memmove(__result, __first, __last - __first);
00118 return __result + (__last - __first);
00119 }
00120
00121 inline wchar_t*
00122 uninitialized_copy(const wchar_t* __first, const wchar_t* __last,
00123 wchar_t* __result)
00124 {
00125 memmove(__result, __first, sizeof(wchar_t) * (__last - __first));
00126 return __result + (__last - __first);
00127 }
00128
00129
00130
00131 template <class _InputIter, class _Size, class _ForwardIter>
00132 pair<_InputIter, _ForwardIter>
00133 __uninitialized_copy_n(_InputIter __first, _Size __count,
00134 _ForwardIter __result,
00135 input_iterator_tag)
00136 {
00137 _ForwardIter __cur = __result;
00138 __STL_TRY {
00139 for ( ; __count > 0 ; --__count, ++__first, ++__cur)
00140 _Construct(&*__cur, *__first);
00141 return pair<_InputIter, _ForwardIter>(__first, __cur);
00142 }
00143 __STL_UNWIND(_Destroy(__result, __cur));
00144 }
00145
00146 template <class _RandomAccessIter, class _Size, class _ForwardIter>
00147 inline pair<_RandomAccessIter, _ForwardIter>
00148 __uninitialized_copy_n(_RandomAccessIter __first, _Size __count,
00149 _ForwardIter __result,
00150 random_access_iterator_tag) {
00151 _RandomAccessIter __last = __first + __count;
00152 return pair<_RandomAccessIter, _ForwardIter>(
00153 __last,
00154 uninitialized_copy(__first, __last, __result));
00155 }
00156
00157 template <class _InputIter, class _Size, class _ForwardIter>
00158 inline pair<_InputIter, _ForwardIter>
00159 __uninitialized_copy_n(_InputIter __first, _Size __count,
00160 _ForwardIter __result) {
00161 return __uninitialized_copy_n(__first, __count, __result,
00162 __iterator_category(__first));
00163 }
00164
00165 template <class _InputIter, class _Size, class _ForwardIter>
00166 inline pair<_InputIter, _ForwardIter>
00167 uninitialized_copy_n(_InputIter __first, _Size __count,
00168 _ForwardIter __result) {
00169 return __uninitialized_copy_n(__first, __count, __result,
00170 __iterator_category(__first));
00171 }
00172
00173
00174
00175 template <class _ForwardIter, class _Tp>
00176 inline void
00177 __uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last,
00178 const _Tp& __x, __true_type)
00179 {
00180 fill(__first, __last, __x);
00181 }
00182
00183 template <class _ForwardIter, class _Tp>
00184 void
00185 __uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last,
00186 const _Tp& __x, __false_type)
00187 {
00188 _ForwardIter __cur = __first;
00189 __STL_TRY {
00190 for ( ; __cur != __last; ++__cur)
00191 _Construct(&*__cur, __x);
00192 }
00193 __STL_UNWIND(_Destroy(__first, __cur));
00194 }
00195
00196 template <class _ForwardIter, class _Tp, class _Tp1>
00197 inline void __uninitialized_fill(_ForwardIter __first,
00198 _ForwardIter __last, const _Tp& __x, _Tp1*)
00199 {
00200 typedef typename __type_traits<_Tp1>::is_POD_type _Is_POD;
00201 __uninitialized_fill_aux(__first, __last, __x, _Is_POD());
00202
00203 }
00204
00205 template <class _ForwardIter, class _Tp>
00206 inline void uninitialized_fill(_ForwardIter __first,
00207 _ForwardIter __last,
00208 const _Tp& __x)
00209 {
00210 __uninitialized_fill(__first, __last, __x, __value_type(__first));
00211 }
00212
00213
00214
00215 template <class _ForwardIter, class _Size, class _Tp>
00216 inline _ForwardIter
00217 __uninitialized_fill_n_aux(_ForwardIter __first, _Size __n,
00218 const _Tp& __x, __true_type)
00219 {
00220 return fill_n(__first, __n, __x);
00221 }
00222
00223 template <class _ForwardIter, class _Size, class _Tp>
00224 _ForwardIter
00225 __uninitialized_fill_n_aux(_ForwardIter __first, _Size __n,
00226 const _Tp& __x, __false_type)
00227 {
00228 _ForwardIter __cur = __first;
00229 __STL_TRY {
00230 for ( ; __n > 0; --__n, ++__cur)
00231 _Construct(&*__cur, __x);
00232 return __cur;
00233 }
00234 __STL_UNWIND(_Destroy(__first, __cur));
00235 }
00236
00237 template <class _ForwardIter, class _Size, class _Tp, class _Tp1>
00238 inline _ForwardIter
00239 __uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x, _Tp1*)
00240 {
00241 typedef typename __type_traits<_Tp1>::is_POD_type _Is_POD;
00242 return __uninitialized_fill_n_aux(__first, __n, __x, _Is_POD());
00243 }
00244
00245 template <class _ForwardIter, class _Size, class _Tp>
00246 inline _ForwardIter
00247 uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x)
00248 {
00249 return __uninitialized_fill_n(__first, __n, __x, __value_type(__first));
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 template <class _InputIter1, class _InputIter2, class _ForwardIter>
00261 inline _ForwardIter
00262 __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
00263 _InputIter2 __first2, _InputIter2 __last2,
00264 _ForwardIter __result)
00265 {
00266 _ForwardIter __mid = uninitialized_copy(__first1, __last1, __result);
00267 __STL_TRY {
00268 return uninitialized_copy(__first2, __last2, __mid);
00269 }
00270 __STL_UNWIND(_Destroy(__result, __mid));
00271 }
00272
00273
00274
00275
00276 template <class _ForwardIter, class _Tp, class _InputIter>
00277 inline _ForwardIter
00278 __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid,
00279 const _Tp& __x,
00280 _InputIter __first, _InputIter __last)
00281 {
00282 uninitialized_fill(__result, __mid, __x);
00283 __STL_TRY {
00284 return uninitialized_copy(__first, __last, __mid);
00285 }
00286 __STL_UNWIND(_Destroy(__result, __mid));
00287 }
00288
00289
00290
00291
00292 template <class _InputIter, class _ForwardIter, class _Tp>
00293 inline void
00294 __uninitialized_copy_fill(_InputIter __first1, _InputIter __last1,
00295 _ForwardIter __first2, _ForwardIter __last2,
00296 const _Tp& __x)
00297 {
00298 _ForwardIter __mid2 = uninitialized_copy(__first1, __last1, __first2);
00299 __STL_TRY {
00300 uninitialized_fill(__mid2, __last2, __x);
00301 }
00302 __STL_UNWIND(_Destroy(__first2, __mid2));
00303 }
00304
00305 }
00306
00307 #endif
00308
00309
00310
00311