_uninitialized.h

00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Copyright (c) 1996,1997
00007  * Silicon Graphics Computer Systems, Inc.
00008  *
00009  * Copyright (c) 1997
00010  * Moscow Center for SPARC Technology
00011  *
00012  * Copyright (c) 1999 
00013  * Boris Fomitchev
00014  *
00015  * This material is provided "as is", with absolutely no warranty expressed
00016  * or implied. Any use is at your own risk.
00017  *
00018  * Permission to use or copy this software for any purpose is hereby granted 
00019  * without fee, provided the above notices are retained on all copies.
00020  * Permission to modify the code and to distribute modified code is granted,
00021  * provided the above notices are retained, and a notice that the code was
00022  * modified is included with the above copyright notice.
00023  *
00024  */
00025 
00026 /* NOTE: This is an internal header file, included by other STL headers.
00027  *   You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _STLP_INTERNAL_UNINITIALIZED_H
00031 #define _STLP_INTERNAL_UNINITIALIZED_H
00032 
00033 # ifndef _STLP_CSTRING
00034 #  include <cstring>
00035 # endif
00036 
00037 # ifndef _STLP_INTERNAL_ALGOBASE_H
00038 #  include <stl/_algobase.h>
00039 # endif
00040 
00041 # ifndef _STLP_INTERNAL_CONSTRUCT_H
00042 #  include <stl/_construct.h>
00043 # endif
00044 
00045 _STLP_BEGIN_NAMESPACE
00046 
00047 // uninitialized_copy
00048 
00049 // Valid if copy construction is equivalent to assignment, and if the
00050 //  destructor is trivial.
00051 template <class _InputIter, class _ForwardIter>
00052 inline _ForwardIter 
00053 __uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result,
00054                      const __true_type&) {
00055   return __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _ForwardIter> :: _Ret());
00056 }
00057 
00058 template <class _InputIter, class _ForwardIter>
00059 _STLP_INLINE_LOOP
00060 _ForwardIter 
00061 __uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result,
00062                      const __false_type&)
00063 {
00064   _ForwardIter __cur = __result;
00065   _STLP_TRY {
00066     for ( ; __first != __last; ++__first, ++__cur)
00067       _Construct(&*__cur, *__first);
00068     return __cur;
00069   }
00070   _STLP_UNWIND(_Destroy(__result, __cur));
00071 # ifdef _STLP_THROW_RETURN_BUG
00072   return __cur;
00073 # endif
00074 }
00075 
00076 template <class _InputIter, class _ForwardIter>
00077 inline _ForwardIter
00078 uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result) {
00079   return __uninitialized_copy(__first, __last, __result,  _IS_POD_ITER(__result, _ForwardIter));
00080 }
00081 
00082 inline char* 
00083 uninitialized_copy(const char* __first, const char* __last, char* __result) {
00084   return  (char*)__copy_trivial (__first, __last, __result);
00085 }
00086 
00087 #  ifdef _STLP_HAS_WCHAR_T // dwa 8/15/97
00088 inline wchar_t* 
00089 uninitialized_copy(const wchar_t* __first, const wchar_t* __last, wchar_t* __result) {
00090   return  (wchar_t*)__copy_trivial (__first, __last, __result);
00091 }
00092 #  endif /* _STLP_HAS_WCHAR_T */
00093 
00094 # ifndef _STLP_NO_EXTENSIONS
00095 // uninitialized_copy_n (not part of the C++ standard)
00096 
00097 template <class _InputIter, class _Size, class _ForwardIter>
00098 _STLP_INLINE_LOOP 
00099 pair<_InputIter, _ForwardIter>
00100 __uninitialized_copy_n(_InputIter __first, _Size __count,
00101                        _ForwardIter __result,
00102                        const input_iterator_tag &)
00103 {
00104   _ForwardIter __cur = __result;
00105   _STLP_TRY {
00106     for ( ; __count > 0 ; --__count, ++__first, ++__cur) 
00107       _Construct(&*__cur, *__first);
00108     return pair<_InputIter, _ForwardIter>(__first, __cur);
00109   }
00110   _STLP_UNWIND(_Destroy(__result, __cur));
00111 # ifdef _STLP_THROW_RETURN_BUG
00112   return pair<_InputIter, _ForwardIter>(__first, __cur);
00113 # endif
00114 }
00115 
00116 # if defined(_STLP_NONTEMPL_BASE_MATCH_BUG) 
00117 template <class _InputIterator, class _Size, class _ForwardIterator>
00118 inline pair<_InputIterator, _ForwardIterator>
00119 __uninitialized_copy_n(_InputIterator __first, _Size __count,
00120                        _ForwardIterator __result,
00121                        const forward_iterator_tag &) {
00122   return __uninitialized_copy_n(__first, __count, __result, input_iterator_tag());
00123 }
00124 
00125 template <class _InputIterator, class _Size, class _ForwardIterator>
00126 inline pair<_InputIterator, _ForwardIterator>
00127 __uninitialized_copy_n(_InputIterator __first, _Size __count,
00128                        _ForwardIterator __result,
00129                        const bidirectional_iterator_tag &) {
00130   return __uninitialized_copy_n(__first, __count, __result, input_iterator_tag());
00131 }
00132 # endif
00133 
00134 
00135 template <class _RandomAccessIter, class _Size, class _ForwardIter>
00136 inline pair<_RandomAccessIter, _ForwardIter>
00137 __uninitialized_copy_n(_RandomAccessIter __first, _Size __count, _ForwardIter __result, const random_access_iterator_tag &) {
00138   _RandomAccessIter __last = __first + __count;
00139   return pair<_RandomAccessIter, _ForwardIter>( __last, __uninitialized_copy(__first, __last, __result, 
00140                                                                              _IS_POD_ITER(__result, _ForwardIter)));
00141 }
00142 
00143 // this is used internally in <rope> , which is extension itself.
00144 template <class _InputIter, class _Size, class _ForwardIter>
00145 inline pair<_InputIter, _ForwardIter>
00146 uninitialized_copy_n(_InputIter __first, _Size __count,
00147                      _ForwardIter __result) {
00148   return __uninitialized_copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
00149 }
00150 # endif /* _STLP_NO_EXTENSIONS */
00151 
00152 // Valid if copy construction is equivalent to assignment, and if the
00153 // destructor is trivial.
00154 template <class _ForwardIter, class _Tp>
00155 inline void
00156 __uninitialized_fill(_ForwardIter __first, _ForwardIter __last, 
00157                      const _Tp& __x, const __true_type&) {
00158   _STLP_STD::fill(__first, __last, __x);
00159 }
00160 
00161 template <class _ForwardIter, class _Tp>
00162 _STLP_INLINE_LOOP void
00163 __uninitialized_fill(_ForwardIter __first, _ForwardIter __last, 
00164                      const _Tp& __x, const __false_type&)
00165 {
00166   _ForwardIter __cur = __first;
00167   _STLP_TRY {
00168     for ( ; __cur != __last; ++__cur)
00169       _Construct(&*__cur, __x);
00170   }
00171   _STLP_UNWIND(_Destroy(__first, __cur));
00172 }
00173 
00174 template <class _ForwardIter, class _Tp>
00175 inline void uninitialized_fill(_ForwardIter __first, _ForwardIter __last,  const _Tp& __x) {
00176   __uninitialized_fill(__first, __last, __x, _IS_POD_ITER(__first, _ForwardIter));
00177 }
00178 
00179 // Valid if copy construction is equivalent to assignment, and if the
00180 //  destructor is trivial.
00181 template <class _ForwardIter, class _Size, class _Tp>
00182 inline _ForwardIter
00183 __uninitialized_fill_n(_ForwardIter __first, _Size __n,
00184                        const _Tp& __x, const __true_type&) {
00185   return _STLP_STD::fill_n(__first, __n, __x);
00186 }
00187 
00188 template <class _ForwardIter, class _Size, class _Tp>
00189 _STLP_INLINE_LOOP _ForwardIter
00190 __uninitialized_fill_n(_ForwardIter __first, _Size __n,
00191                        const _Tp& __x, const __false_type&)
00192 {
00193   _ForwardIter __cur = __first;
00194   _STLP_TRY {
00195     for ( ; __n > 0; --__n, ++__cur)
00196       _Construct(&*__cur, __x);
00197     return __cur;
00198   }
00199   _STLP_UNWIND(_Destroy(__first, __cur));
00200 # ifdef _STLP_THROW_RETURN_BUG
00201   return __cur;
00202 # endif
00203 }
00204 
00205 template <class _ForwardIter, class _Size, class _Tp>
00206 inline _ForwardIter 
00207 uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x) {
00208   return __uninitialized_fill_n(__first, __n, __x, _IS_POD_ITER(__first, _ForwardIter));
00209 }
00210 
00211 // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill, 
00212 // __uninitialized_fill_copy.
00213 
00214 // __uninitialized_copy_copy
00215 // Copies [first1, last1) into [result, result + (last1 - first1)), and
00216 //  copies [first2, last2) into
00217 //  [result, result + (last1 - first1) + (last2 - first2)).
00218 
00219 template <class _InputIter1, class _InputIter2, class _ForwardIter>
00220 inline _ForwardIter
00221 __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
00222                           _InputIter2 __first2, _InputIter2 __last2,
00223                           _ForwardIter __result, __true_type)
00224 {
00225   return __uninitialized_copy(__first2, __last2, 
00226                               __uninitialized_copy(__first1, __last1, __result, __true_type()), __true_type());
00227 }
00228 
00229 template <class _InputIter1, class _InputIter2, class _ForwardIter>
00230 inline _ForwardIter
00231 __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
00232                           _InputIter2 __first2, _InputIter2 __last2,
00233                           _ForwardIter __result, __false_type)
00234 {
00235   _ForwardIter __mid = __uninitialized_copy(__first1, __last1, __result, _IS_POD_ITER(__result, _ForwardIter));
00236   _STLP_TRY {
00237     return __uninitialized_copy(__first2, __last2, __mid , _IS_POD_ITER(__result, _ForwardIter));
00238   }
00239   _STLP_UNWIND(_Destroy(__result, __mid));
00240 # ifdef _STLP_THROW_RETURN_BUG
00241   return __mid;
00242 # endif
00243 }
00244 
00245 // __uninitialized_fill_copy
00246 // Fills [result, mid) with x, and copies [first, last) into
00247 //  [mid, mid + (last - first)).
00248 template <class _ForwardIter, class _Tp, class _InputIter>
00249 inline _ForwardIter 
00250 __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid, const _Tp& __x,
00251                           _InputIter __first, _InputIter __last)
00252 {
00253   typedef typename __type_traits<_Tp>::is_POD_type _I_POD;
00254   __uninitialized_fill(__result, __mid, __x, _I_POD());
00255   _STLP_TRY {
00256     return __uninitialized_copy(__first, __last, __mid, _I_POD());
00257   }
00258   _STLP_UNWIND(_Destroy(__result, __mid));
00259 # ifdef _STLP_THROW_RETURN_BUG
00260   return __result;
00261 # endif
00262 }
00263 
00264 // __uninitialized_copy_fill
00265 // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
00266 //  fills [first2 + (last1 - first1), last2) with x.
00267 template <class _InputIter, class _ForwardIter, class _Tp>
00268 inline void
00269 __uninitialized_copy_fill(_InputIter __first1, _InputIter __last1,
00270                           _ForwardIter __first2, _ForwardIter __last2,
00271                           const _Tp& __x)
00272 {
00273   typedef typename __type_traits<_Tp>::is_POD_type _I_POD;
00274   _ForwardIter __mid2 = __uninitialized_copy(__first1, __last1, __first2, _I_POD());
00275   _STLP_TRY {
00276     __uninitialized_fill(__mid2, __last2, __x, _I_POD());
00277   }
00278   _STLP_UNWIND(_Destroy(__first2, __mid2));
00279 }
00280 
00281 _STLP_END_NAMESPACE
00282 
00283 #endif /* _STLP_INTERNAL_UNINITIALIZED_H */
00284 
00285 // Local Variables:
00286 // mode:C++
00287 // End:

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