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