epoc32/include/stdapis/stlportv5/stl/_construct.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  *
     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_CONSTRUCT_H
    31 #define _STLP_INTERNAL_CONSTRUCT_H
    32 
    33 #if !defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_INTERNAL_CSTRING)
    34 #  include <stl/_cstring.h>
    35 #endif
    36 
    37 #ifndef _STLP_INTERNAL_NEW
    38 #  include <stl/_new.h>
    39 #endif
    40 
    41 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
    42 #  include <stl/_iterator_base.h>
    43 #endif
    44 
    45 #ifndef _STLP_MOVE_CONSTRUCT_FWK_H
    46 #  include <stl/_move_construct_fwk.h>
    47 #endif
    48 
    49 _STLP_BEGIN_NAMESPACE
    50 
    51 template <class _Tp>
    52 inline void __destroy_aux(_Tp* __pointer, const __false_type& /*_Trivial_destructor*/)
    53 { __pointer->~_Tp(); }
    54 
    55 template <class _Tp>
    56 inline void __destroy_aux(_Tp*, const __true_type& /*_Trivial_destructor*/) {}
    57 
    58 template <class _Tp>
    59 inline void _Destroy(_Tp* __pointer) {
    60 #if defined (_STLP_MSVC) && (_STLP_MSVC <= 1010)
    61   __pointer;
    62 #endif
    63   typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
    64   __destroy_aux(__pointer, _Trivial_destructor());
    65 #if defined (_STLP_DEBUG_UNINITIALIZED)
    66   memset(__REINTERPRET_CAST(char*, __pointer), _STLP_SHRED_BYTE, sizeof(_Tp));
    67 #endif
    68 }
    69 
    70 template <class _Tp>
    71 inline void _Destroy_Moved(_Tp* __pointer) {
    72   typedef typename __move_traits<_Tp>::complete _Trivial_destructor;
    73   __destroy_aux(__pointer, _Trivial_destructor());
    74 #if defined (_STLP_DEBUG_UNINITIALIZED)
    75   memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
    76 #endif
    77 }
    78 
    79 #if defined (new)
    80 #  define _STLP_NEW_REDEFINE new
    81 #  undef new
    82 #endif
    83 
    84 #if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
    85 template <class _T1>
    86 inline void _Construct_aux (_T1* __p, const __false_type&) {
    87   _STLP_PLACEMENT_NEW (__p) _T1();
    88 }
    89 
    90 template <class _T1>
    91 inline void _Construct_aux (_T1* __p, const __true_type&) {
    92   _STLP_PLACEMENT_NEW (__p) _T1(0);
    93 }
    94 #endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
    95 
    96 template <class _T1>
    97 inline void _Construct(_T1* __p) {
    98 #if defined (_STLP_DEBUG_UNINITIALIZED)
    99   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
   100 #endif
   101 #if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
   102   _Construct_aux (__p, _HasDefaultZeroValue(__p)._Answer() );
   103 #else
   104   _STLP_PLACEMENT_NEW (__p) _T1();
   105 #endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
   106 }
   107 
   108 template <class _Tp>
   109 inline void _Copy_Construct(_Tp* __p, const _Tp& __val) {
   110 #if defined (_STLP_DEBUG_UNINITIALIZED)
   111   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_Tp));
   112 #endif
   113   _STLP_PLACEMENT_NEW (__p) _Tp(__val);
   114 }
   115 
   116 template <class _T1, class _T2>
   117 inline void _Param_Construct(_T1* __p, const _T2& __val) {
   118 #if defined (_STLP_DEBUG_UNINITIALIZED)
   119   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
   120 #endif
   121   _STLP_PLACEMENT_NEW (__p) _T1(__val);
   122 }
   123 
   124 template <class _T1, class _T2>
   125 inline void _Move_Construct_Aux(_T1* __p, _T2& __val, const __false_type& /*_IsPOD*/) {
   126   _STLP_PLACEMENT_NEW (__p) _T1(_STLP_PRIV _AsMoveSource(__val));
   127 }
   128 
   129 template <class _T1, class _T2>
   130 inline void _Move_Construct_Aux(_T1* __p, _T2& __val, const __true_type& /*_IsPOD*/) {
   131   _STLP_PLACEMENT_NEW (__p) _T1(__val);
   132 }
   133 
   134 template <class _T1, class _T2>
   135 inline void _Move_Construct(_T1* __p, _T2& __val) {
   136 #if defined (_STLP_DEBUG_UNINITIALIZED)
   137   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
   138 #endif
   139   _Move_Construct_Aux(__p, __val, _Is_POD(__p)._Answer());
   140 }
   141 
   142 #if defined(_STLP_NEW_REDEFINE)
   143 #  if defined (DEBUG_NEW)
   144 #    define new DEBUG_NEW
   145 #  endif
   146 #  undef _STLP_NEW_REDEFINE
   147 #endif
   148 
   149 template <class _ForwardIterator, class _Tp>
   150 _STLP_INLINE_LOOP void
   151 __destroy_range_aux(_ForwardIterator __first, _ForwardIterator __last, _Tp*, const __false_type& /*_Trivial_destructor*/) {
   152   for ( ; __first != __last; ++__first) {
   153     __destroy_aux(&(*__first), __false_type());
   154 #if defined (_STLP_DEBUG_UNINITIALIZED)
   155     memset((char*)&(*__first), _STLP_SHRED_BYTE, sizeof(_Tp));
   156 #endif
   157   }
   158 }
   159 
   160 template <class _ForwardIterator, class _Tp>
   161 #if defined (_STLP_DEBUG_UNINITIALIZED)
   162 _STLP_INLINE_LOOP void
   163 __destroy_range_aux(_ForwardIterator __first, _ForwardIterator __last, _Tp*, const __true_type& /*_Trivial_destructor*/) {
   164   for ( ; __first != __last; ++__first)
   165     memset((char*)&(*__first), _STLP_SHRED_BYTE, sizeof(_Tp));
   166 }
   167 #else
   168 inline void
   169 __destroy_range_aux(_ForwardIterator, _ForwardIterator, _Tp*, const __true_type& /*_Trivial_destructor*/) {}
   170 #endif
   171 
   172 template <class _ForwardIterator, class _Tp>
   173 inline void
   174 __destroy_range(_ForwardIterator __first, _ForwardIterator __last, _Tp *__ptr) {
   175   typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
   176   __destroy_range_aux(__first, __last, __ptr, _Trivial_destructor());
   177 }
   178 
   179 template <class _ForwardIterator>
   180 inline void _Destroy_Range(_ForwardIterator __first, _ForwardIterator __last) {
   181   __destroy_range(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
   182 }
   183 
   184 inline void _Destroy_Range(char*, char*) {}
   185 #if defined (_STLP_HAS_WCHAR_T) // dwa 8/15/97
   186 inline void _Destroy_Range(wchar_t*, wchar_t*) {}
   187 inline void _Destroy_Range(const wchar_t*, const wchar_t*) {}
   188 #endif
   189 
   190 template <class _ForwardIterator, class _Tp>
   191 inline void
   192 __destroy_mv_srcs(_ForwardIterator __first, _ForwardIterator __last, _Tp *__ptr) {
   193   typedef typename __move_traits<_Tp>::complete _CompleteMove;
   194   __destroy_range_aux(__first, __last, __ptr, _CompleteMove());
   195 }
   196 
   197 template <class _ForwardIterator>
   198 inline void _Destroy_Moved_Range(_ForwardIterator __first, _ForwardIterator __last) {
   199   __destroy_mv_srcs(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
   200 }
   201 
   202 #if defined (_STLP_DEF_CONST_DEF_PARAM_BUG)
   203 // Those adaptors are here to fix common compiler bug regarding builtins:
   204 // expressions like int k = int() should initialize k to 0
   205 template <class _Tp>
   206 inline _Tp __default_constructed_aux(_Tp*, const __false_type&) {
   207   return _Tp();
   208 }
   209 template <class _Tp>
   210 inline _Tp __default_constructed_aux(_Tp*, const __true_type&) {
   211   return _Tp(0);
   212 }
   213 
   214 template <class _Tp>
   215 inline _Tp __default_constructed(_Tp* __p) {
   216   return __default_constructed_aux(__p, _HasDefaultZeroValue(__p)._Answer());
   217 }
   218 
   219 #  define _STLP_DEFAULT_CONSTRUCTED(_TTp) __default_constructed((_TTp*)0)
   220 #else
   221 #  define _STLP_DEFAULT_CONSTRUCTED(_TTp) _TTp()
   222 #endif /* _STLP_DEF_CONST_DEF_PARAM_BUG */
   223 
   224 
   225 #if !defined (_STLP_NO_ANACHRONISMS)
   226 // --------------------------------------------------
   227 // Old names from the HP STL.
   228 
   229 template <class _T1, class _T2>
   230 inline void construct(_T1* __p, const _T2& __val) {_Param_Construct(__p, __val); }
   231 template <class _T1>
   232 inline void construct(_T1* __p) { _STLP_STD::_Construct(__p); }
   233 template <class _Tp>
   234 inline void destroy(_Tp* __pointer) {  _STLP_STD::_Destroy(__pointer); }
   235 template <class _ForwardIterator>
   236 inline void destroy(_ForwardIterator __first, _ForwardIterator __last) { _STLP_STD::_Destroy_Range(__first, __last); }
   237 #endif /* _STLP_NO_ANACHRONISMS */
   238 
   239 _STLP_END_NAMESPACE
   240 
   241 #endif /* _STLP_INTERNAL_CONSTRUCT_H */
   242 
   243 // Local Variables:
   244 // mode:C++
   245 // End: