Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

stl_uninitialized.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  *
00015  * Copyright (c) 1996,1997
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */
00026 
00027 /* NOTE: This is an internal header file, included by other STL headers.
00028  *   You should not attempt to use it directly.
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 // uninitialized_copy
00040 
00041 // Valid if copy construction is equivalent to assignment, and if the
00042 //  destructor is trivial.
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 // uninitialized_copy_n (not part of the C++ standard)
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 // Valid if copy construction is equivalent to assignment, and if the
00145 // destructor is trivial.
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 // Valid if copy construction is equivalent to assignment, and if the
00185 //  destructor is trivial.
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 // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill, 
00224 // __uninitialized_fill_copy.
00225 
00226 // __uninitialized_copy_copy
00227 // Copies [first1, last1) into [result, result + (last1 - first1)), and
00228 //  copies [first2, last2) into
00229 //  [result, result + (last1 - first1) + (last2 - first2)).
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 // __uninitialized_fill_copy
00245 // Fills [result, mid) with x, and copies [first, last) into
00246 //  [mid, mid + (last - first)).
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 // __uninitialized_copy_fill
00261 // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
00262 //  fills [first2 + (last1 - first1), last2) with x.
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 } // namespace std
00277 
00278 #endif /* _CPP_BITS_STL_UNINITIALIZED_H */
00279 
00280 // Local Variables:
00281 // mode:C++
00282 // End:

Generated at Tue May 1 16:28:40 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001