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.
williamr@2
     1
/*
williamr@4
     2
 *
williamr@2
     3
 * Copyright (c) 1994
williamr@2
     4
 * Hewlett-Packard Company
williamr@2
     5
 *
williamr@2
     6
 * Copyright (c) 1996,1997
williamr@2
     7
 * Silicon Graphics Computer Systems, Inc.
williamr@2
     8
 *
williamr@2
     9
 * Copyright (c) 1997
williamr@2
    10
 * Moscow Center for SPARC Technology
williamr@2
    11
 *
williamr@4
    12
 * Copyright (c) 1999
williamr@2
    13
 * Boris Fomitchev
williamr@2
    14
 *
williamr@2
    15
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
    16
 * or implied. Any use is at your own risk.
williamr@2
    17
 *
williamr@4
    18
 * Permission to use or copy this software for any purpose is hereby granted
williamr@2
    19
 * without fee, provided the above notices are retained on all copies.
williamr@2
    20
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    21
 * provided the above notices are retained, and a notice that the code was
williamr@2
    22
 * modified is included with the above copyright notice.
williamr@2
    23
 *
williamr@2
    24
 */
williamr@2
    25
williamr@2
    26
/* NOTE: This is an internal header file, included by other STL headers.
williamr@2
    27
 *   You should not attempt to use it directly.
williamr@2
    28
 */
williamr@2
    29
williamr@2
    30
#ifndef _STLP_INTERNAL_CONSTRUCT_H
williamr@2
    31
#define _STLP_INTERNAL_CONSTRUCT_H
williamr@2
    32
williamr@4
    33
#if !defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_INTERNAL_CSTRING)
williamr@4
    34
#  include <stl/_cstring.h>
williamr@4
    35
#endif
williamr@2
    36
williamr@4
    37
#ifndef _STLP_INTERNAL_NEW
williamr@2
    38
#  include <stl/_new.h>
williamr@4
    39
#endif
williamr@2
    40
williamr@2
    41
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
williamr@4
    42
#  include <stl/_iterator_base.h>
williamr@4
    43
#endif
williamr@4
    44
williamr@4
    45
#ifndef _STLP_MOVE_CONSTRUCT_FWK_H
williamr@4
    46
#  include <stl/_move_construct_fwk.h>
williamr@2
    47
#endif
williamr@2
    48
williamr@2
    49
_STLP_BEGIN_NAMESPACE
williamr@2
    50
williamr@2
    51
template <class _Tp>
williamr@4
    52
inline void __destroy_aux(_Tp* __pointer, const __false_type& /*_Trivial_destructor*/)
williamr@4
    53
{ __pointer->~_Tp(); }
williamr@4
    54
williamr@2
    55
template <class _Tp>
williamr@4
    56
inline void __destroy_aux(_Tp*, const __true_type& /*_Trivial_destructor*/) {}
williamr@2
    57
williamr@2
    58
template <class _Tp>
williamr@2
    59
inline void _Destroy(_Tp* __pointer) {
williamr@4
    60
#if defined (_STLP_MSVC) && (_STLP_MSVC <= 1010)
williamr@2
    61
  __pointer;
williamr@4
    62
#endif
williamr@2
    63
  typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
williamr@2
    64
  __destroy_aux(__pointer, _Trivial_destructor());
williamr@4
    65
#if defined (_STLP_DEBUG_UNINITIALIZED)
williamr@4
    66
  memset(__REINTERPRET_CAST(char*, __pointer), _STLP_SHRED_BYTE, sizeof(_Tp));
williamr@4
    67
#endif
williamr@2
    68
}
williamr@2
    69
williamr@4
    70
template <class _Tp>
williamr@4
    71
inline void _Destroy_Moved(_Tp* __pointer) {
williamr@4
    72
  typedef typename __move_traits<_Tp>::complete _Trivial_destructor;
williamr@4
    73
  __destroy_aux(__pointer, _Trivial_destructor());
williamr@4
    74
#if defined (_STLP_DEBUG_UNINITIALIZED)
williamr@4
    75
  memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
williamr@4
    76
#endif
williamr@4
    77
}
williamr@2
    78
williamr@4
    79
#if defined (new)
williamr@4
    80
#  define _STLP_NEW_REDEFINE new
williamr@4
    81
#  undef new
williamr@4
    82
#endif
williamr@4
    83
williamr@4
    84
#if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
williamr@2
    85
template <class _T1>
williamr@2
    86
inline void _Construct_aux (_T1* __p, const __false_type&) {
williamr@4
    87
  _STLP_PLACEMENT_NEW (__p) _T1();
williamr@2
    88
}
williamr@2
    89
williamr@2
    90
template <class _T1>
williamr@2
    91
inline void _Construct_aux (_T1* __p, const __true_type&) {
williamr@4
    92
  _STLP_PLACEMENT_NEW (__p) _T1(0);
williamr@2
    93
}
williamr@4
    94
#endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
williamr@2
    95
williamr@2
    96
template <class _T1>
williamr@2
    97
inline void _Construct(_T1* __p) {
williamr@4
    98
#if defined (_STLP_DEBUG_UNINITIALIZED)
williamr@2
    99
  memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
williamr@4
   100
#endif
williamr@4
   101
#if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
williamr@4
   102
  _Construct_aux (__p, _HasDefaultZeroValue(__p)._Answer() );
williamr@4
   103
#else
williamr@2
   104
  _STLP_PLACEMENT_NEW (__p) _T1();
williamr@4
   105
#endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
williamr@2
   106
}
williamr@2
   107
williamr@4
   108
template <class _Tp>
williamr@4
   109
inline void _Copy_Construct(_Tp* __p, const _Tp& __val) {
williamr@4
   110
#if defined (_STLP_DEBUG_UNINITIALIZED)
williamr@4
   111
  memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_Tp));
williamr@4
   112
#endif
williamr@4
   113
  _STLP_PLACEMENT_NEW (__p) _Tp(__val);
williamr@2
   114
}
williamr@2
   115
williamr@4
   116
template <class _T1, class _T2>
williamr@4
   117
inline void _Param_Construct(_T1* __p, const _T2& __val) {
williamr@4
   118
#if defined (_STLP_DEBUG_UNINITIALIZED)
williamr@4
   119
  memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
williamr@4
   120
#endif
williamr@4
   121
  _STLP_PLACEMENT_NEW (__p) _T1(__val);
williamr@4
   122
}
williamr@4
   123
williamr@4
   124
template <class _T1, class _T2>
williamr@4
   125
inline void _Move_Construct_Aux(_T1* __p, _T2& __val, const __false_type& /*_IsPOD*/) {
williamr@4
   126
  _STLP_PLACEMENT_NEW (__p) _T1(_STLP_PRIV _AsMoveSource(__val));
williamr@4
   127
}
williamr@4
   128
williamr@4
   129
template <class _T1, class _T2>
williamr@4
   130
inline void _Move_Construct_Aux(_T1* __p, _T2& __val, const __true_type& /*_IsPOD*/) {
williamr@4
   131
  _STLP_PLACEMENT_NEW (__p) _T1(__val);
williamr@4
   132
}
williamr@4
   133
williamr@4
   134
template <class _T1, class _T2>
williamr@4
   135
inline void _Move_Construct(_T1* __p, _T2& __val) {
williamr@4
   136
#if defined (_STLP_DEBUG_UNINITIALIZED)
williamr@4
   137
  memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
williamr@4
   138
#endif
williamr@4
   139
  _Move_Construct_Aux(__p, __val, _Is_POD(__p)._Answer());
williamr@4
   140
}
williamr@4
   141
williamr@4
   142
#if defined(_STLP_NEW_REDEFINE)
williamr@4
   143
#  if defined (DEBUG_NEW)
williamr@4
   144
#    define new DEBUG_NEW
williamr@4
   145
#  endif
williamr@4
   146
#  undef _STLP_NEW_REDEFINE
williamr@4
   147
#endif
williamr@2
   148
williamr@2
   149
template <class _ForwardIterator, class _Tp>
williamr@4
   150
_STLP_INLINE_LOOP void
williamr@4
   151
__destroy_range_aux(_ForwardIterator __first, _ForwardIterator __last, _Tp*, const __false_type& /*_Trivial_destructor*/) {
williamr@4
   152
  for ( ; __first != __last; ++__first) {
williamr@4
   153
    __destroy_aux(&(*__first), __false_type());
williamr@4
   154
#if defined (_STLP_DEBUG_UNINITIALIZED)
williamr@4
   155
    memset((char*)&(*__first), _STLP_SHRED_BYTE, sizeof(_Tp));
williamr@4
   156
#endif
williamr@4
   157
  }
williamr@4
   158
}
williamr@4
   159
williamr@4
   160
template <class _ForwardIterator, class _Tp>
williamr@4
   161
#if defined (_STLP_DEBUG_UNINITIALIZED)
williamr@4
   162
_STLP_INLINE_LOOP void
williamr@4
   163
__destroy_range_aux(_ForwardIterator __first, _ForwardIterator __last, _Tp*, const __true_type& /*_Trivial_destructor*/) {
williamr@4
   164
  for ( ; __first != __last; ++__first)
williamr@4
   165
    memset((char*)&(*__first), _STLP_SHRED_BYTE, sizeof(_Tp));
williamr@4
   166
}
williamr@4
   167
#else
williamr@4
   168
inline void
williamr@4
   169
__destroy_range_aux(_ForwardIterator, _ForwardIterator, _Tp*, const __true_type& /*_Trivial_destructor*/) {}
williamr@4
   170
#endif
williamr@4
   171
williamr@4
   172
template <class _ForwardIterator, class _Tp>
williamr@4
   173
inline void
williamr@4
   174
__destroy_range(_ForwardIterator __first, _ForwardIterator __last, _Tp *__ptr) {
williamr@2
   175
  typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
williamr@4
   176
  __destroy_range_aux(__first, __last, __ptr, _Trivial_destructor());
williamr@2
   177
}
williamr@2
   178
williamr@2
   179
template <class _ForwardIterator>
williamr@4
   180
inline void _Destroy_Range(_ForwardIterator __first, _ForwardIterator __last) {
williamr@4
   181
  __destroy_range(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
williamr@2
   182
}
williamr@2
   183
williamr@4
   184
inline void _Destroy_Range(char*, char*) {}
williamr@4
   185
#if defined (_STLP_HAS_WCHAR_T) // dwa 8/15/97
williamr@4
   186
inline void _Destroy_Range(wchar_t*, wchar_t*) {}
williamr@4
   187
inline void _Destroy_Range(const wchar_t*, const wchar_t*) {}
williamr@4
   188
#endif
williamr@2
   189
williamr@4
   190
template <class _ForwardIterator, class _Tp>
williamr@4
   191
inline void
williamr@4
   192
__destroy_mv_srcs(_ForwardIterator __first, _ForwardIterator __last, _Tp *__ptr) {
williamr@4
   193
  typedef typename __move_traits<_Tp>::complete _CompleteMove;
williamr@4
   194
  __destroy_range_aux(__first, __last, __ptr, _CompleteMove());
williamr@4
   195
}
williamr@4
   196
williamr@4
   197
template <class _ForwardIterator>
williamr@4
   198
inline void _Destroy_Moved_Range(_ForwardIterator __first, _ForwardIterator __last) {
williamr@4
   199
  __destroy_mv_srcs(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
williamr@4
   200
}
williamr@4
   201
williamr@4
   202
#if defined (_STLP_DEF_CONST_DEF_PARAM_BUG)
williamr@4
   203
// Those adaptors are here to fix common compiler bug regarding builtins:
williamr@4
   204
// expressions like int k = int() should initialize k to 0
williamr@4
   205
template <class _Tp>
williamr@4
   206
inline _Tp __default_constructed_aux(_Tp*, const __false_type&) {
williamr@4
   207
  return _Tp();
williamr@4
   208
}
williamr@4
   209
template <class _Tp>
williamr@4
   210
inline _Tp __default_constructed_aux(_Tp*, const __true_type&) {
williamr@4
   211
  return _Tp(0);
williamr@4
   212
}
williamr@4
   213
williamr@4
   214
template <class _Tp>
williamr@4
   215
inline _Tp __default_constructed(_Tp* __p) {
williamr@4
   216
  return __default_constructed_aux(__p, _HasDefaultZeroValue(__p)._Answer());
williamr@4
   217
}
williamr@4
   218
williamr@4
   219
#  define _STLP_DEFAULT_CONSTRUCTED(_TTp) __default_constructed((_TTp*)0)
williamr@4
   220
#else
williamr@4
   221
#  define _STLP_DEFAULT_CONSTRUCTED(_TTp) _TTp()
williamr@4
   222
#endif /* _STLP_DEF_CONST_DEF_PARAM_BUG */
williamr@4
   223
williamr@4
   224
williamr@4
   225
#if !defined (_STLP_NO_ANACHRONISMS)
williamr@2
   226
// --------------------------------------------------
williamr@2
   227
// Old names from the HP STL.
williamr@2
   228
williamr@2
   229
template <class _T1, class _T2>
williamr@4
   230
inline void construct(_T1* __p, const _T2& __val) {_Param_Construct(__p, __val); }
williamr@2
   231
template <class _T1>
williamr@4
   232
inline void construct(_T1* __p) { _STLP_STD::_Construct(__p); }
williamr@2
   233
template <class _Tp>
williamr@2
   234
inline void destroy(_Tp* __pointer) {  _STLP_STD::_Destroy(__pointer); }
williamr@2
   235
template <class _ForwardIterator>
williamr@4
   236
inline void destroy(_ForwardIterator __first, _ForwardIterator __last) { _STLP_STD::_Destroy_Range(__first, __last); }
williamr@4
   237
#endif /* _STLP_NO_ANACHRONISMS */
williamr@2
   238
williamr@2
   239
_STLP_END_NAMESPACE
williamr@2
   240
williamr@2
   241
#endif /* _STLP_INTERNAL_CONSTRUCT_H */
williamr@2
   242
williamr@2
   243
// Local Variables:
williamr@2
   244
// mode:C++
williamr@2
   245
// End: