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