ossrv_pub/utility_apis/inc/stdapis/stlport/stl/_uninitialized.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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   _STLP_LEAVE_VOLATILE _ForwardIter __cur = __result;
       
    65   _STLP_TRY  {
       
    66     for ( ; __first != __last; ++__first, ++__cur)
       
    67       _Construct(&*__cur, *__first);
       
    68     //    return __cur;
       
    69   }
       
    70   _STLP_UNWIND (_STLP_STD::_Destroy(__result, __cur)); 
       
    71   return __cur;
       
    72 }
       
    73 
       
    74 template <class _InputIter, class _ForwardIter>
       
    75 inline _ForwardIter
       
    76 uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result) {
       
    77   return __uninitialized_copy(__first, __last, __result,  _IS_POD_ITER(__result, _ForwardIter));
       
    78 }
       
    79 
       
    80 inline char* 
       
    81 uninitialized_copy(const char* __first, const char* __last, char* __result) {
       
    82   return  (char*)__copy_trivial (__first, __last, __result);
       
    83 }
       
    84 
       
    85 #  ifdef _STLP_HAS_WCHAR_T // dwa 8/15/97
       
    86 inline wchar_t* 
       
    87 uninitialized_copy(const wchar_t* __first, const wchar_t* __last, wchar_t* __result) {
       
    88   return  (wchar_t*)__copy_trivial (__first, __last, __result);
       
    89 }
       
    90 #  endif /* _STLP_HAS_WCHAR_T */
       
    91 
       
    92 # ifndef _STLP_NO_EXTENSIONS
       
    93 // uninitialized_copy_n (not part of the C++ standard)
       
    94 
       
    95 template <class _InputIter, class _Size, class _ForwardIter>
       
    96 // _STLP_INLINE_LOOP 
       
    97 pair<_InputIter, _ForwardIter>
       
    98 __uninitialized_copy_n(_InputIter __first, _Size __count,
       
    99                        _ForwardIter __result,
       
   100                        const input_iterator_tag &)
       
   101 {
       
   102   _STLP_LEAVE_VOLATILE  _ForwardIter __cur = __result;
       
   103   _STLP_TRY {
       
   104     for ( ; __count > 0 ; --__count, ++__first, ++__cur) 
       
   105       _Construct(&*__cur, *__first);
       
   106     //    return pair<_InputIter, _ForwardIter>(__first, __cur);
       
   107   }
       
   108   _STLP_UNWIND(_STLP_STD::_Destroy(__result, __cur));
       
   109 
       
   110   return pair<_InputIter, _ForwardIter>(__first, __cur);
       
   111 
       
   112 }
       
   113 
       
   114 # if defined(_STLP_NONTEMPL_BASE_MATCH_BUG) 
       
   115 template <class _InputIterator, class _Size, class _ForwardIterator>
       
   116 inline pair<_InputIterator, _ForwardIterator>
       
   117 __uninitialized_copy_n(_InputIterator __first, _Size __count,
       
   118                        _ForwardIterator __result,
       
   119                        const forward_iterator_tag &) {
       
   120   return __uninitialized_copy_n(__first, __count, __result, input_iterator_tag());
       
   121 }
       
   122 
       
   123 template <class _InputIterator, class _Size, class _ForwardIterator>
       
   124 inline pair<_InputIterator, _ForwardIterator>
       
   125 __uninitialized_copy_n(_InputIterator __first, _Size __count,
       
   126                        _ForwardIterator __result,
       
   127                        const bidirectional_iterator_tag &) {
       
   128   return __uninitialized_copy_n(__first, __count, __result, input_iterator_tag());
       
   129 }
       
   130 # endif
       
   131 
       
   132 
       
   133 template <class _RandomAccessIter, class _Size, class _ForwardIter>
       
   134 inline pair<_RandomAccessIter, _ForwardIter>
       
   135 __uninitialized_copy_n(_RandomAccessIter __first, _Size __count, _ForwardIter __result, const random_access_iterator_tag &) {
       
   136   _RandomAccessIter __last = __first + __count;
       
   137   return pair<_RandomAccessIter, _ForwardIter>( __last, __uninitialized_copy(__first, __last, __result, 
       
   138                                                                              _IS_POD_ITER(__result, _ForwardIter)));
       
   139 }
       
   140 
       
   141 // this is used internally in <rope> , which is extension itself.
       
   142 template <class _InputIter, class _Size, class _ForwardIter>
       
   143 inline pair<_InputIter, _ForwardIter>
       
   144 uninitialized_copy_n(_InputIter __first, _Size __count,
       
   145                      _ForwardIter __result) {
       
   146   return __uninitialized_copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
       
   147 }
       
   148 # endif /* _STLP_NO_EXTENSIONS */
       
   149 
       
   150 // Valid if copy construction is equivalent to assignment, and if the
       
   151 // destructor is trivial.
       
   152 template <class _ForwardIter, class _Tp>
       
   153 inline void
       
   154 __uninitialized_fill(_ForwardIter __first, _ForwardIter __last, 
       
   155                      const _Tp& __x, const __true_type&) {
       
   156   _STLP_STD::fill(__first, __last, __x);
       
   157 }
       
   158 
       
   159 template <class _ForwardIter, class _Tp>
       
   160 // _STLP_INLINE_LOOP 
       
   161 void
       
   162 __uninitialized_fill(_ForwardIter __first, _ForwardIter __last, 
       
   163                      const _Tp& __x, const __false_type&)
       
   164 {
       
   165   _STLP_LEAVE_VOLATILE  _ForwardIter __cur = __first;
       
   166   _STLP_TRY {
       
   167     for ( ; __cur != __last; ++__cur)
       
   168       _Construct(&*__cur, __x);
       
   169   }
       
   170   _STLP_UNWIND(_STLP_STD::_Destroy(__first, __cur));
       
   171 }
       
   172 
       
   173 template <class _ForwardIter, class _Tp>
       
   174 inline void uninitialized_fill(_ForwardIter __first, _ForwardIter __last,  const _Tp& __x) {
       
   175   __uninitialized_fill(__first, __last, __x, _IS_POD_ITER(__first, _ForwardIter));
       
   176 }
       
   177 
       
   178 // Valid if copy construction is equivalent to assignment, and if the
       
   179 //  destructor is trivial.
       
   180 template <class _ForwardIter, class _Size, class _Tp>
       
   181 inline _ForwardIter
       
   182 __uninitialized_fill_n(_ForwardIter __first, _Size __n,
       
   183                        const _Tp& __x, const __true_type&) {
       
   184   return _STLP_STD::fill_n(__first, __n, __x);
       
   185 }
       
   186 
       
   187 template <class _ForwardIter, class _Size, class _Tp>
       
   188 //_STLP_INLINE_LOOP 
       
   189 _ForwardIter
       
   190 __uninitialized_fill_n(_ForwardIter __first, _Size __n,
       
   191                        const _Tp& __x, const __false_type&)
       
   192 {
       
   193   _STLP_LEAVE_VOLATILE  _ForwardIter __cur = __first;
       
   194   _STLP_TRY {
       
   195     for ( ; __n > 0; --__n, ++__cur)
       
   196       _Construct(&*__cur, __x);
       
   197     //    return __cur;
       
   198   }
       
   199   _STLP_UNWIND(_STLP_STD::_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 
       
   231 _ForwardIter
       
   232 __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
       
   233                           _InputIter2 __first2, _InputIter2 __last2,
       
   234                           _ForwardIter __result, __false_type)
       
   235 {
       
   236    _STLP_LEAVE_VOLATILE _ForwardIter __mid = __uninitialized_copy(__first1, __last1, __result, _IS_POD_ITER(__result, _ForwardIter));
       
   237 
       
   238   _STLP_TRY {
       
   239     return __uninitialized_copy(__first2, __last2, __mid , _IS_POD_ITER(__result, _ForwardIter));
       
   240   }
       
   241   _STLP_UNWIND (_STLP_STD::_Destroy(__result, __mid));
       
   242 # ifdef _STLP_THROW_RETURN_BUG
       
   243   return __mid;
       
   244 # endif
       
   245 }
       
   246 
       
   247 // __uninitialized_fill_copy
       
   248 // Fills [result, mid) with x, and copies [first, last) into
       
   249 //  [mid, mid + (last - first)).
       
   250 template <class _ForwardIter, class _Tp, class _InputIter>
       
   251 // inline 
       
   252 _ForwardIter 
       
   253 __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid, const _Tp& __x,
       
   254                           _InputIter __first, _InputIter __last)
       
   255 {
       
   256   typedef typename __type_traits<_Tp>::is_POD_type _I_POD;
       
   257   __uninitialized_fill(__result, __mid, __x, _I_POD());
       
   258   _STLP_TRY {
       
   259     return __uninitialized_copy(__first, __last, __mid, _I_POD());
       
   260   }
       
   261   _STLP_UNWIND (_STLP_STD::_Destroy(__result, __mid));
       
   262 # ifdef _STLP_THROW_RETURN_BUG
       
   263   return __result;
       
   264 # endif
       
   265 }
       
   266 
       
   267 // __uninitialized_copy_fill
       
   268 // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
       
   269 //  fills [first2 + (last1 - first1), last2) with x.
       
   270 template <class _InputIter, class _ForwardIter, class _Tp>
       
   271 // inline 
       
   272 void
       
   273 __uninitialized_copy_fill(_InputIter __first1, _InputIter __last1,
       
   274                           _ForwardIter __first2, _ForwardIter __last2,
       
   275                           const _Tp& __x)
       
   276 {
       
   277   typedef typename __type_traits<_Tp>::is_POD_type _I_POD;
       
   278   _ForwardIter __mid2 = __uninitialized_copy(__first1, __last1, __first2, _I_POD());
       
   279   _STLP_TRY {
       
   280     __uninitialized_fill(__mid2, __last2, __x, _I_POD());
       
   281   }
       
   282   _STLP_UNWIND(_STLP_STD::_Destroy(__first2, __mid2));
       
   283 }
       
   284 
       
   285 _STLP_END_NAMESPACE
       
   286 
       
   287 #endif /* _STLP_INTERNAL_UNINITIALIZED_H */
       
   288 
       
   289 // Local Variables:
       
   290 // mode:C++
       
   291 // End: