home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _uninitialized.h < prev    next >
C/C++ Source or Header  |  2001-05-29  |  10KB  |  288 lines

  1. /*
  2.  *
  3.  * Copyright (c) 1994
  4.  * Hewlett-Packard Company
  5.  *
  6.  * Copyright (c) 1996,1997
  7.  * Silicon Graphics Computer Systems, Inc.
  8.  *
  9.  * Copyright (c) 1997
  10.  * Moscow Center for SPARC Technology
  11.  *
  12.  * Copyright (c) 1999 
  13.  * Boris Fomitchev
  14.  *
  15.  * This material is provided "as is", with absolutely no warranty expressed
  16.  * or implied. Any use is at your own risk.
  17.  *
  18.  * Permission to use or copy this software for any purpose is hereby granted 
  19.  * without fee, provided the above notices are retained on all copies.
  20.  * Permission to modify the code and to distribute modified code is granted,
  21.  * provided the above notices are retained, and a notice that the code was
  22.  * modified is included with the above copyright notice.
  23.  *
  24.  */
  25.  
  26. /* NOTE: This is an internal header file, included by other STL headers.
  27.  *   You should not attempt to use it directly.
  28.  */
  29.  
  30. #ifndef _STLP_INTERNAL_UNINITIALIZED_H
  31. #define _STLP_INTERNAL_UNINITIALIZED_H
  32.  
  33. # ifndef _STLP_CSTRING
  34. #  include <cstring>
  35. # endif
  36.  
  37. # ifndef _STLP_INTERNAL_ALGOBASE_H
  38. #  include <stl/_algobase.h>
  39. # endif
  40.  
  41. # ifndef _STLP_INTERNAL_CONSTRUCT_H
  42. #  include <stl/_construct.h>
  43. # endif
  44.  
  45. _STLP_BEGIN_NAMESPACE
  46.  
  47. // uninitialized_copy
  48.  
  49. // Valid if copy construction is equivalent to assignment, and if the
  50. //  destructor is trivial.
  51. template <class _InputIter, class _ForwardIter>
  52. inline _ForwardIter 
  53. __uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result,
  54.                      const __true_type&) {
  55.   return __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _ForwardIter> :: _Ret());
  56. }
  57.  
  58. template <class _InputIter, class _ForwardIter>
  59. _STLP_INLINE_LOOP
  60. _ForwardIter 
  61. __uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result,
  62.                      const __false_type&)
  63. {
  64.   _ForwardIter __cur = __result;
  65.   _STLP_TRY {
  66.     for ( ; __first != __last; ++__first, ++__cur)
  67.       _Construct(&*__cur, *__first);
  68.     return __cur;
  69.   }
  70.   _STLP_UNWIND(_Destroy(__result, __cur));
  71. # ifdef _STLP_THROW_RETURN_BUG
  72.   return __cur;
  73. # endif
  74. }
  75.  
  76. template <class _InputIter, class _ForwardIter>
  77. inline _ForwardIter
  78. uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result) {
  79.   return __uninitialized_copy(__first, __last, __result,  _IS_POD_ITER(__result, _ForwardIter));
  80. }
  81.  
  82. inline char* 
  83. uninitialized_copy(const char* __first, const char* __last, char* __result) {
  84.   return  (char*)__copy_trivial (__first, __last, __result);
  85. }
  86.  
  87. #  ifdef _STLP_HAS_WCHAR_T // dwa 8/15/97
  88. inline wchar_t* 
  89. uninitialized_copy(const wchar_t* __first, const wchar_t* __last, wchar_t* __result) {
  90.   return  (wchar_t*)__copy_trivial (__first, __last, __result);
  91. }
  92. #  endif /* _STLP_HAS_WCHAR_T */
  93.  
  94. # ifndef _STLP_NO_EXTENSIONS
  95. // uninitialized_copy_n (not part of the C++ standard)
  96.  
  97. template <class _InputIter, class _Size, class _ForwardIter>
  98. _STLP_INLINE_LOOP 
  99. pair<_InputIter, _ForwardIter>
  100. __uninitialized_copy_n(_InputIter __first, _Size __count,
  101.                        _ForwardIter __result,
  102.                        const input_iterator_tag &)
  103. {
  104.   _ForwardIter __cur = __result;
  105.   _STLP_TRY {
  106.     for ( ; __count > 0 ; --__count, ++__first, ++__cur) 
  107.       _Construct(&*__cur, *__first);
  108.     return pair<_InputIter, _ForwardIter>(__first, __cur);
  109.   }
  110.   _STLP_UNWIND(_Destroy(__result, __cur));
  111. # ifdef _STLP_THROW_RETURN_BUG
  112.   return pair<_InputIter, _ForwardIter>(__first, __cur);
  113. # endif
  114. }
  115.  
  116. # if defined(_STLP_NONTEMPL_BASE_MATCH_BUG) 
  117. template <class _InputIterator, class _Size, class _ForwardIterator>
  118. inline pair<_InputIterator, _ForwardIterator>
  119. __uninitialized_copy_n(_InputIterator __first, _Size __count,
  120.                        _ForwardIterator __result,
  121.                        const forward_iterator_tag &) {
  122.   return __uninitialized_copy_n(__first, __count, __result, input_iterator_tag());
  123. }
  124.  
  125. template <class _InputIterator, class _Size, class _ForwardIterator>
  126. inline pair<_InputIterator, _ForwardIterator>
  127. __uninitialized_copy_n(_InputIterator __first, _Size __count,
  128.                        _ForwardIterator __result,
  129.                        const bidirectional_iterator_tag &) {
  130.   return __uninitialized_copy_n(__first, __count, __result, input_iterator_tag());
  131. }
  132. # endif
  133.  
  134.  
  135. template <class _RandomAccessIter, class _Size, class _ForwardIter>
  136. inline pair<_RandomAccessIter, _ForwardIter>
  137. __uninitialized_copy_n(_RandomAccessIter __first, _Size __count, _ForwardIter __result, const random_access_iterator_tag &) {
  138.   _RandomAccessIter __last = __first + __count;
  139.   return pair<_RandomAccessIter, _ForwardIter>( __last, __uninitialized_copy(__first, __last, __result, 
  140.                                                                              _IS_POD_ITER(__result, _ForwardIter)));
  141. }
  142.  
  143. // this is used internally in <rope> , which is extension itself.
  144. template <class _InputIter, class _Size, class _ForwardIter>
  145. inline pair<_InputIter, _ForwardIter>
  146. uninitialized_copy_n(_InputIter __first, _Size __count,
  147.                      _ForwardIter __result) {
  148.   return __uninitialized_copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
  149. }
  150. # endif /* _STLP_NO_EXTENSIONS */
  151.  
  152. // Valid if copy construction is equivalent to assignment, and if the
  153. // destructor is trivial.
  154. template <class _ForwardIter, class _Tp>
  155. inline void
  156. __uninitialized_fill(_ForwardIter __first, _ForwardIter __last, 
  157.                      const _Tp& __x, const __true_type&) {
  158.   _STLP_STD::fill(__first, __last, __x);
  159. }
  160.  
  161. template <class _ForwardIter, class _Tp>
  162. _STLP_INLINE_LOOP void
  163. __uninitialized_fill(_ForwardIter __first, _ForwardIter __last, 
  164.                      const _Tp& __x, const __false_type&)
  165. {
  166.   _ForwardIter __cur = __first;
  167.   _STLP_TRY {
  168.     for ( ; __cur != __last; ++__cur)
  169.       _Construct(&*__cur, __x);
  170.   }
  171.   _STLP_UNWIND(_Destroy(__first, __cur));
  172. }
  173.  
  174. template <class _ForwardIter, class _Tp>
  175. inline void uninitialized_fill(_ForwardIter __first, _ForwardIter __last,  const _Tp& __x) {
  176.   __uninitialized_fill(__first, __last, __x, _IS_POD_ITER(__first, _ForwardIter));
  177. }
  178.  
  179. // Valid if copy construction is equivalent to assignment, and if the
  180. //  destructor is trivial.
  181. template <class _ForwardIter, class _Size, class _Tp>
  182. inline _ForwardIter
  183. __uninitialized_fill_n(_ForwardIter __first, _Size __n,
  184.                        const _Tp& __x, const __true_type&) {
  185.   return _STLP_STD::fill_n(__first, __n, __x);
  186. }
  187.  
  188. template <class _ForwardIter, class _Size, class _Tp>
  189. _STLP_INLINE_LOOP _ForwardIter
  190. __uninitialized_fill_n(_ForwardIter __first, _Size __n,
  191.                        const _Tp& __x, const __false_type&)
  192. {
  193.   _ForwardIter __cur = __first;
  194.   _STLP_TRY {
  195.     for ( ; __n > 0; --__n, ++__cur)
  196.       _Construct(&*__cur, __x);
  197.     return __cur;
  198.   }
  199.   _STLP_UNWIND(_Destroy(__first, __cur));
  200. # ifdef _STLP_THROW_RETURN_BUG
  201.   return __cur;
  202. # endif
  203. }
  204.  
  205. template <class _ForwardIter, class _Size, class _Tp>
  206. inline _ForwardIter 
  207. uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x) {
  208.   return __uninitialized_fill_n(__first, __n, __x, _IS_POD_ITER(__first, _ForwardIter));
  209. }
  210.  
  211. // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill, 
  212. // __uninitialized_fill_copy.
  213.  
  214. // __uninitialized_copy_copy
  215. // Copies [first1, last1) into [result, result + (last1 - first1)), and
  216. //  copies [first2, last2) into
  217. //  [result, result + (last1 - first1) + (last2 - first2)).
  218.  
  219. template <class _InputIter1, class _InputIter2, class _ForwardIter>
  220. inline _ForwardIter
  221. __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
  222.                           _InputIter2 __first2, _InputIter2 __last2,
  223.                           _ForwardIter __result, __true_type)
  224. {
  225.   return __uninitialized_copy(__first2, __last2, 
  226.                               __uninitialized_copy(__first1, __last1, __result, __true_type()), __true_type());
  227. }
  228.  
  229. template <class _InputIter1, class _InputIter2, class _ForwardIter>
  230. inline _ForwardIter
  231. __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
  232.                           _InputIter2 __first2, _InputIter2 __last2,
  233.                           _ForwardIter __result, __false_type)
  234. {
  235.   _ForwardIter __mid = __uninitialized_copy(__first1, __last1, __result, _IS_POD_ITER(__result, _ForwardIter));
  236.   _STLP_TRY {
  237.     return __uninitialized_copy(__first2, __last2, __mid , _IS_POD_ITER(__result, _ForwardIter));
  238.   }
  239.   _STLP_UNWIND(_Destroy(__result, __mid));
  240. # ifdef _STLP_THROW_RETURN_BUG
  241.   return __mid;
  242. # endif
  243. }
  244.  
  245. // __uninitialized_fill_copy
  246. // Fills [result, mid) with x, and copies [first, last) into
  247. //  [mid, mid + (last - first)).
  248. template <class _ForwardIter, class _Tp, class _InputIter>
  249. inline _ForwardIter 
  250. __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid, const _Tp& __x,
  251.                           _InputIter __first, _InputIter __last)
  252. {
  253.   typedef typename __type_traits<_Tp>::is_POD_type _I_POD;
  254.   __uninitialized_fill(__result, __mid, __x, _I_POD());
  255.   _STLP_TRY {
  256.     return __uninitialized_copy(__first, __last, __mid, _I_POD());
  257.   }
  258.   _STLP_UNWIND(_Destroy(__result, __mid));
  259. # ifdef _STLP_THROW_RETURN_BUG
  260.   return __result;
  261. # endif
  262. }
  263.  
  264. // __uninitialized_copy_fill
  265. // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
  266. //  fills [first2 + (last1 - first1), last2) with x.
  267. template <class _InputIter, class _ForwardIter, class _Tp>
  268. inline void
  269. __uninitialized_copy_fill(_InputIter __first1, _InputIter __last1,
  270.                           _ForwardIter __first2, _ForwardIter __last2,
  271.                           const _Tp& __x)
  272. {
  273.   typedef typename __type_traits<_Tp>::is_POD_type _I_POD;
  274.   _ForwardIter __mid2 = __uninitialized_copy(__first1, __last1, __first2, _I_POD());
  275.   _STLP_TRY {
  276.     __uninitialized_fill(__mid2, __last2, __x, _I_POD());
  277.   }
  278.   _STLP_UNWIND(_Destroy(__first2, __mid2));
  279. }
  280.  
  281. _STLP_END_NAMESPACE
  282.  
  283. #endif /* _STLP_INTERNAL_UNINITIALIZED_H */
  284.  
  285. // Local Variables:
  286. // mode:C++
  287. // End:
  288.