epoc32/include/stdapis/stlportv5/stl/_uninitialized.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     3  *
     4  * Copyright (c) 1994
     5  * Hewlett-Packard Company
     6  *
     7  * Copyright (c) 1996,1997
     8  * Silicon Graphics Computer Systems, Inc.
     9  *
    10  * Copyright (c) 1997
    11  * Moscow Center for SPARC Technology
    12  *
    13  * Copyright (c) 1999
    14  * Boris Fomitchev
    15  *
    16  * This material is provided "as is", with absolutely no warranty expressed
    17  * or implied. Any use is at your own risk.
    18  *
    19  * Permission to use or copy this software for any purpose is hereby granted
    20  * without fee, provided the above notices are retained on all copies.
    21  * Permission to modify the code and to distribute modified code is granted,
    22  * provided the above notices are retained, and a notice that the code was
    23  * modified is included with the above copyright notice.
    24  *
    25  */
    26 
    27 /* NOTE: This is an internal header file, included by other STL headers.
    28  *   You should not attempt to use it directly.
    29  */
    30 
    31 #ifndef _STLP_INTERNAL_UNINITIALIZED_H
    32 #define _STLP_INTERNAL_UNINITIALIZED_H
    33 
    34 #ifndef _STLP_INTERNAL_CSTRING
    35 #  include <stl/_cstring.h>
    36 #endif
    37 
    38 #ifndef _STLP_INTERNAL_ALGOBASE_H
    39 #  include <stl/_algobase.h>
    40 #endif
    41 
    42 #ifndef _STLP_INTERNAL_CONSTRUCT_H
    43 #  include <stl/_construct.h>
    44 #endif
    45 
    46 _STLP_BEGIN_NAMESPACE
    47 
    48 _STLP_MOVE_TO_PRIV_NAMESPACE
    49 
    50 // uninitialized_copy
    51 
    52 template <class _InputIter, class _OutputIter, class _Distance>
    53 inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
    54                            _OutputIter __result, _Distance*) {
    55   _OutputIter __cur = __result;
    56   _STLP_TRY {
    57     for ( ; __first != __last; ++__first, ++__cur)
    58       _Param_Construct(&*__cur, *__first);
    59     return __cur;
    60   }
    61   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __cur))
    62   _STLP_RET_AFTER_THROW(__cur)
    63 }
    64 
    65 template <class _InputIter, class _OutputIter, class _Distance>
    66 inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
    67                            _OutputIter __result, const input_iterator_tag &, _Distance* __d)
    68 { return __ucopy(__first, __last, __result, __d); }
    69 
    70 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
    71 template <class _InputIter, class _OutputIter, class _Distance>
    72 inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
    73                            _OutputIter __result, const forward_iterator_tag &, _Distance* __d)
    74 { return __ucopy(__first, __last, __result, __d); }
    75 
    76 template <class _InputIter, class _OutputIter, class _Distance>
    77 inline _OutputIter __ucopy(_InputIter __first, _InputIter __last,
    78                            _OutputIter __result, const bidirectional_iterator_tag &, _Distance* __d)
    79 { return __ucopy(__first, __last, __result, __d); }
    80 #endif
    81 
    82 template <class _RandomAccessIter, class _OutputIter, class _Distance>
    83 inline _OutputIter __ucopy(_RandomAccessIter __first, _RandomAccessIter __last,
    84                            _OutputIter __result, const random_access_iterator_tag &, _Distance*) {
    85   _OutputIter __cur = __result;
    86   _STLP_TRY {
    87     for (_Distance __n = __last - __first; __n > 0; --__n) {
    88       _Param_Construct(&*__cur, *__first);
    89       ++__first;
    90       ++__cur;
    91     }
    92     return __cur;
    93   }
    94   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __cur))
    95   _STLP_RET_AFTER_THROW(__cur)
    96 }
    97 
    98 //Used internaly
    99 template <class _RandomAccessIter, class _OutputIter>
   100 inline _OutputIter __ucopy(_RandomAccessIter __first, _RandomAccessIter __last, _OutputIter __result)
   101 { return __ucopy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0); }
   102 
   103 inline void*
   104 __ucopy_trivial(const void* __first, const void* __last, void* __result) {
   105   //dums: this version can use memcpy (__copy_trivial can't)
   106   return (__last == __first) ? __result :
   107     ((char*)memcpy(__result, __first, ((const char*)__last - (const char*)__first))) +
   108     ((const char*)__last - (const char*)__first);
   109 }
   110 
   111 template <class _InputIter, class _OutputIter>
   112 inline _OutputIter __ucopy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
   113                                 const __false_type& /*TrivialUCopy*/)
   114 { return __ucopy(__first, __last, __result, random_access_iterator_tag(), (ptrdiff_t*)0); }
   115 
   116 template <class _InputIter, class _OutputIter>
   117 inline _OutputIter __ucopy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result,
   118                                 const __true_type& /*TrivialUCopy*/) {
   119   // we know they all pointers, so this cast is OK
   120   //  return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result));
   121   return (_OutputIter)__ucopy_trivial(__first, __last, __result);
   122 }
   123 
   124 template <class _InputIter, class _OutputIter>
   125 inline _OutputIter __ucopy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
   126                                const __true_type& /*BothPtrType*/) {
   127   return __ucopy_ptrs(__first, __last, __result,
   128                       _UseTrivialUCopy(_STLP_VALUE_TYPE(__first, _InputIter),
   129                                        _STLP_VALUE_TYPE(__result, _OutputIter))._Answer());
   130 }
   131 
   132 template <class _InputIter, class _OutputIter>
   133 inline _OutputIter __ucopy_aux(_InputIter __first, _InputIter __last, _OutputIter __result,
   134                                const __false_type& /*BothPtrType*/) {
   135   return __ucopy(__first, __last, __result,
   136                  _STLP_ITERATOR_CATEGORY(__first, _InputIter),
   137                  _STLP_DISTANCE_TYPE(__first, _InputIter));
   138 }
   139 
   140 _STLP_MOVE_TO_STD_NAMESPACE
   141 
   142 template <class _InputIter, class _ForwardIter>
   143 inline _ForwardIter
   144 uninitialized_copy(_InputIter __first, _InputIter __last, _ForwardIter __result)
   145 { return _STLP_PRIV __ucopy_aux(__first, __last, __result, _BothPtrType< _InputIter, _ForwardIter>::_Answer()); }
   146 
   147 inline char*
   148 uninitialized_copy(const char* __first, const char* __last, char* __result)
   149 { return  (char*)_STLP_PRIV __ucopy_trivial(__first, __last, __result); }
   150 
   151 #  if defined (_STLP_HAS_WCHAR_T) // dwa 8/15/97
   152 inline wchar_t*
   153 uninitialized_copy(const wchar_t* __first, const wchar_t* __last, wchar_t* __result)
   154 { return  (wchar_t*)_STLP_PRIV __ucopy_trivial (__first, __last, __result); }
   155 #  endif
   156 
   157 // uninitialized_copy_n (not part of the C++ standard)
   158 _STLP_MOVE_TO_PRIV_NAMESPACE
   159 
   160 template <class _InputIter, class _Size, class _ForwardIter>
   161 _STLP_INLINE_LOOP
   162 pair<_InputIter, _ForwardIter>
   163 __ucopy_n(_InputIter __first, _Size __count, _ForwardIter __result,
   164           const input_iterator_tag &) {
   165   _ForwardIter __cur = __result;
   166   _STLP_TRY {
   167     for ( ; __count > 0 ; --__count, ++__first, ++__cur)
   168       _Param_Construct(&*__cur, *__first);
   169     return pair<_InputIter, _ForwardIter>(__first, __cur);
   170   }
   171   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __cur))
   172   _STLP_RET_AFTER_THROW((pair<_InputIter, _ForwardIter>(__first, __cur)))
   173 }
   174 
   175 #  if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
   176 template <class _InputIter, class _Size, class _ForwardIterator>
   177 inline pair<_InputIter, _ForwardIterator>
   178 __ucopy_n(_InputIter __first, _Size __count,
   179                        _ForwardIterator __result,
   180                        const forward_iterator_tag &)
   181 { return __ucopy_n(__first, __count, __result, input_iterator_tag()); }
   182 
   183 template <class _InputIter, class _Size, class _ForwardIterator>
   184 inline pair<_InputIter, _ForwardIterator>
   185 __ucopy_n(_InputIter __first, _Size __count,
   186                        _ForwardIterator __result,
   187                        const bidirectional_iterator_tag &)
   188 { return __ucopy_n(__first, __count, __result, input_iterator_tag()); }
   189 #  endif
   190 
   191 template <class _RandomAccessIter, class _Size, class _ForwardIter>
   192 inline pair<_RandomAccessIter, _ForwardIter>
   193 __ucopy_n(_RandomAccessIter __first, _Size __count, _ForwardIter __result,
   194                        const random_access_iterator_tag &) {
   195   _RandomAccessIter __last = __first + __count;
   196   return pair<_RandomAccessIter, _ForwardIter>(__last, uninitialized_copy(__first, __last, __result));
   197 }
   198 
   199 // This is used internally in <rope> , which is extension itself.
   200 template <class _InputIter, class _Size, class _ForwardIter>
   201 inline pair<_InputIter, _ForwardIter>
   202 __ucopy_n(_InputIter __first, _Size __count, _ForwardIter __result)
   203 { return _STLP_PRIV __ucopy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); }
   204 
   205 #if !defined (_STLP_NO_EXTENSIONS)
   206 
   207 _STLP_MOVE_TO_STD_NAMESPACE
   208 
   209 template <class _InputIter, class _Size, class _ForwardIter>
   210 inline pair<_InputIter, _ForwardIter>
   211 uninitialized_copy_n(_InputIter __first, _Size __count, _ForwardIter __result)
   212 { return _STLP_PRIV __ucopy_n(__first, __count, __result); }
   213 
   214 _STLP_MOVE_TO_PRIV_NAMESPACE
   215 
   216 #endif
   217 
   218 template <class _ForwardIter, class _Tp, class _Distance>
   219 inline void __ufill(_ForwardIter __first, _ForwardIter __last, const _Tp& __x, _Distance*) {
   220   _ForwardIter __cur = __first;
   221   _STLP_TRY {
   222     for ( ; __cur != __last; ++__cur)
   223       _Param_Construct(&*__cur, __x);
   224   }
   225   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first, __cur))
   226 }
   227 
   228 template <class _ForwardIter, class _Tp, class _Distance>
   229 inline void __ufill(_ForwardIter __first, _ForwardIter __last,
   230                     const _Tp& __x, const input_iterator_tag &, _Distance* __d)
   231 { __ufill(__first, __last, __x, __d); }
   232 
   233 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
   234 template <class _ForwardIter, class _Tp, class _Distance>
   235 inline void __ufill(_ForwardIter __first, _ForwardIter __last,
   236                     const _Tp& __x, const forward_iterator_tag &, _Distance* __d)
   237 { __ufill(__first, __last, __x, __d); }
   238 
   239 template <class _ForwardIter, class _Tp, class _Distance>
   240 inline void __ufill(_ForwardIter __first, _ForwardIter __last,
   241                     const _Tp& __x, const bidirectional_iterator_tag &, _Distance* __d)
   242 { __ufill(__first, __last, __x, __d); }
   243 #endif
   244 
   245 template <class _ForwardIter, class _Tp, class _Distance>
   246 inline void __ufill(_ForwardIter __first, _ForwardIter __last,
   247                     const _Tp& __x, const random_access_iterator_tag &, _Distance*) {
   248   _ForwardIter __cur = __first;
   249   _STLP_TRY {
   250     for (_Distance __n = __last - __first; __n > 0; --__n, ++__cur)
   251       _Param_Construct(&*__cur, __x);
   252   }
   253   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first, __cur))
   254 }
   255 
   256 _STLP_MOVE_TO_STD_NAMESPACE
   257 
   258 template <class _ForwardIter, class _Tp>
   259 inline void uninitialized_fill(_ForwardIter __first, _ForwardIter __last,  const _Tp& __x) {
   260   _STLP_PRIV __ufill(__first, __last, __x,
   261                      _STLP_ITERATOR_CATEGORY(__first, _ForwardIter),
   262                      _STLP_DISTANCE_TYPE(__first, _ForwardIter));
   263 }
   264 
   265 // Specialization: for one-byte types we can use memset.
   266 inline void uninitialized_fill(unsigned char* __first, unsigned char* __last,
   267                                const unsigned char& __val) {
   268   unsigned char __tmp = __val;
   269   memset(__first, __tmp, __last - __first);
   270 }
   271 #if !defined (_STLP_NO_SIGNED_BUILTINS)
   272 inline void uninitialized_fill(signed char* __first, signed char* __last,
   273                                const signed char& __val) {
   274   signed char __tmp = __val;
   275   memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
   276 }
   277 #endif
   278 inline void uninitialized_fill(char* __first, char* __last, const char& __val) {
   279   char __tmp = __val;
   280   memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
   281 }
   282 
   283 _STLP_MOVE_TO_PRIV_NAMESPACE
   284 
   285 template <class _ForwardIter, class _Size, class _Tp>
   286 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x) {
   287   _ForwardIter __cur = __first;
   288   _STLP_TRY {
   289     for ( ; __n > 0; --__n, ++__cur)
   290       _Param_Construct(&*__cur, __x);
   291   }
   292   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first, __cur))
   293   return __cur;
   294 }
   295 
   296 template <class _ForwardIter, class _Size, class _Tp>
   297 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
   298                               const input_iterator_tag &)
   299 { return __ufill_n(__first, __n, __x); }
   300 
   301 #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
   302 template <class _ForwardIter, class _Size, class _Tp>
   303 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
   304                               const forward_iterator_tag &)
   305 { return __ufill_n(__first, __n, __x); }
   306 
   307 template <class _ForwardIter, class _Size, class _Tp>
   308 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
   309                               const bidirectional_iterator_tag &)
   310 { return __ufill_n(__first, __n, __x); }
   311 #endif
   312 
   313 template <class _ForwardIter, class _Size, class _Tp>
   314 inline _ForwardIter __uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x) {
   315   _ForwardIter __last = __first + __n;
   316   __ufill(__first, __last, __x, random_access_iterator_tag(), (ptrdiff_t*)0);
   317   return __last;
   318 }
   319 
   320 template <class _ForwardIter, class _Size, class _Tp>
   321 inline _ForwardIter __ufill_n(_ForwardIter __first, _Size __n, const _Tp& __x,
   322                               const random_access_iterator_tag &)
   323 { return __uninitialized_fill_n(__first, __n, __x); }
   324 
   325 /* __uninitialized_init is an internal algo to init a range with a value
   326  * built using default constructor. It is only called with pointer as
   327  * iterator.
   328  */
   329 template <class _ForwardIter, class _Size, class _Tp>
   330 inline _ForwardIter __uinit_aux_aux(_ForwardIter __first, _Size __n, const _Tp& __val,
   331                                     const __false_type& /*_HasDefaultZero*/)
   332 { return __uninitialized_fill_n(__first, __n, __val); }
   333 
   334 template <class _ForwardIter, class _Size, class _Tp>
   335 inline _ForwardIter __uinit_aux_aux(_ForwardIter __first, _Size __n, const _Tp& /*__val */,
   336                                     const __true_type& /*_HasDefaultZero*/) { 	
   337   memset((unsigned char*)__first, 0, __n * sizeof(_Tp));
   338   return __first + __n;
   339 }
   340 
   341 template <class _ForwardIter, class _Size, class _Tp>
   342 inline _ForwardIter __uinit_aux(_ForwardIter __first, _Size __n, const _Tp&,
   343                                 const __true_type& /*_TrivialInit*/)
   344 { return __first + __n; }
   345 
   346 template <class _ForwardIter, class _Size, class _Tp>
   347 inline _ForwardIter __uinit_aux(_ForwardIter __first, _Size __n, const _Tp& __val,
   348                                 const __false_type& /*_TrivialInit*/)
   349 { return __uinit_aux_aux(__first, __n, __val, _HasDefaultZeroValue(__first)._Answer()); }
   350 
   351 template <class _ForwardIter, class _Size, class _Tp>
   352 inline _ForwardIter __uninitialized_init(_ForwardIter __first, _Size __n, const _Tp& __val)
   353 { return __uinit_aux(__first, __n, __val, _UseTrivialInit(__first)._Answer()); }
   354 
   355 _STLP_MOVE_TO_STD_NAMESPACE
   356 
   357 template <class _ForwardIter, class _Size, class _Tp>
   358 inline void
   359 uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x)
   360 { _STLP_PRIV __ufill_n(__first, __n, __x, _STLP_ITERATOR_CATEGORY(__first, _ForwardIter)); }
   361 
   362 // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
   363 // __uninitialized_fill_copy.
   364 
   365 // __uninitialized_copy_copy
   366 // Copies [first1, last1) into [result, result + (last1 - first1)), and
   367 //  copies [first2, last2) into
   368 //  [result + (last1 - first1), result + (last1 - first1) + (last2 - first2)).
   369 
   370 _STLP_MOVE_TO_PRIV_NAMESPACE
   371 
   372 template <class _InputIter1, class _InputIter2, class _ForwardIter>
   373 inline _ForwardIter
   374 __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
   375                           _InputIter2 __first2, _InputIter2 __last2,
   376                           _ForwardIter __result)
   377 { return uninitialized_copy(__first2, __last2, uninitialized_copy(__first1, __last1, __result)); }
   378 
   379 // __uninitialized_fill_copy
   380 // Fills [result, mid) with x, and copies [first, last) into
   381 //  [mid, mid + (last - first)).
   382 template <class _ForwardIter, class _Tp, class _InputIter>
   383 inline _ForwardIter
   384 __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid, const _Tp& __x,
   385                           _InputIter __first, _InputIter __last) {
   386   uninitialized_fill(__result, __mid, __x);
   387   _STLP_TRY {
   388     return uninitialized_copy(__first, __last, __mid);
   389   }
   390   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__result, __mid))
   391   _STLP_RET_AFTER_THROW(__result)
   392 }
   393 
   394 // __uninitialized_copy_fill
   395 // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
   396 //  fills [first2 + (last1 - first1), last2) with x.
   397 template <class _Iter, class _Tp>
   398 inline void
   399 __uninitialized_copy_fill(_Iter __first1, _Iter __last1, _Iter __first2, _Iter __last2,
   400                           const _Tp& __x) {
   401   _Iter __mid2 = uninitialized_copy(__first1, __last1, __first2);
   402   _STLP_TRY {
   403     uninitialized_fill(__mid2, __last2, __x);
   404   }
   405   _STLP_UNWIND(_STLP_STD::_Destroy_Range(__first2, __mid2))
   406 }
   407 
   408 /* __uninitialized_move:
   409  * This function is used internaly and only with pointers as iterators.
   410  */
   411 template <class _InputIter, class _ForwardIter, class _TrivialUCpy>
   412 inline _ForwardIter
   413 __uninitialized_move(_InputIter __first, _InputIter __last, _ForwardIter __result,
   414                      _TrivialUCpy __trivial_ucpy, const __false_type& /*_Movable*/)
   415 { return __ucopy_ptrs(__first, __last, __result, __trivial_ucpy); }
   416 
   417 template <class _InputIter, class _ForwardIter, class _TrivialUCpy>
   418 _STLP_INLINE_LOOP
   419 _ForwardIter
   420 __uninitialized_move(_InputIter __first, _InputIter __last, _ForwardIter __result,
   421                      _TrivialUCpy , const __true_type& /*_Movable*/) {
   422   //Move constructor should not throw so we do not need to take care of exceptions here.
   423   for (ptrdiff_t __n = __last - __first ; __n > 0; --__n) {
   424     _Move_Construct(&*__result, *__first);
   425     ++__first; ++__result;
   426   }
   427   return __result;
   428 }
   429 
   430 _STLP_MOVE_TO_STD_NAMESPACE
   431 
   432 _STLP_END_NAMESPACE
   433 
   434 #endif /* _STLP_INTERNAL_UNINITIALIZED_H */
   435 
   436 // Local Variables:
   437 // mode:C++
   438 // End: