stl_uninitialized.h

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

Generated on Mon Jun 5 10:20:45 2006 for Intelligence.kdevelop by  doxygen 1.4.6