Copyright (C) 2000-2012 |
Whole document tree stl_uninitialized.hGo to the documentation of this file.00001 // Raw memory manipulators -*- C++ -*- 00002 00003 // Copyright (C) 2001 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00019 // USA. 00020 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 /* 00031 * 00032 * Copyright (c) 1994 00033 * Hewlett-Packard Company 00034 * 00035 * Permission to use, copy, modify, distribute and sell this software 00036 * and its documentation for any purpose is hereby granted without fee, 00037 * provided that the above copyright notice appear in all copies and 00038 * that both that copyright notice and this permission notice appear 00039 * in supporting documentation. Hewlett-Packard Company makes no 00040 * representations about the suitability of this software for any 00041 * purpose. It is provided "as is" without express or implied warranty. 00042 * 00043 * 00044 * Copyright (c) 1996,1997 00045 * Silicon Graphics Computer Systems, Inc. 00046 * 00047 * Permission to use, copy, modify, distribute and sell this software 00048 * and its documentation for any purpose is hereby granted without fee, 00049 * provided that the above copyright notice appear in all copies and 00050 * that both that copyright notice and this permission notice appear 00051 * in supporting documentation. Silicon Graphics makes no 00052 * representations about the suitability of this software for any 00053 * purpose. It is provided "as is" without express or implied warranty. 00054 */ 00055 00056 /* NOTE: This is an internal header file, included by other STL headers. 00057 * You should not attempt to use it directly. 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 // uninitialized_copy 00069 00070 // Valid if copy construction is equivalent to assignment, and if the 00071 // destructor is trivial. 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 // uninitialized_copy_n (not part of the C++ standard) 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 // Valid if copy construction is equivalent to assignment, and if the 00174 // destructor is trivial. 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 // Valid if copy construction is equivalent to assignment, and if the 00214 // destructor is trivial. 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 // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill, 00253 // __uninitialized_fill_copy. 00254 00255 // __uninitialized_copy_copy 00256 // Copies [first1, last1) into [result, result + (last1 - first1)), and 00257 // copies [first2, last2) into 00258 // [result, result + (last1 - first1) + (last2 - first2)). 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 // __uninitialized_fill_copy 00274 // Fills [result, mid) with x, and copies [first, last) into 00275 // [mid, mid + (last - first)). 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 // __uninitialized_copy_fill 00290 // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and 00291 // fills [first2 + (last1 - first1), last2) with x. 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 } // namespace std 00306 00307 #endif /* _CPP_BITS_STL_UNINITIALIZED_H */ 00308 00309 // Local Variables: 00310 // mode:C++ 00311 // End: Generated on Mon Apr 8 03:11:45 2002 for libstdc++-v3 Source by 1.2.15 |