4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
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.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_CONSTRUCT_H
31 #define _STLP_INTERNAL_CONSTRUCT_H
33 #if !defined (_STLP_DEBUG_UNINITIALIZED) && !defined (_STLP_INTERNAL_CSTRING)
34 # include <stl/_cstring.h>
37 #ifndef _STLP_INTERNAL_NEW
38 # include <stl/_new.h>
41 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
42 # include <stl/_iterator_base.h>
45 #ifndef _STLP_MOVE_CONSTRUCT_FWK_H
46 # include <stl/_move_construct_fwk.h>
52 inline void __destroy_aux(_Tp* __pointer, const __false_type& /*_Trivial_destructor*/)
53 { __pointer->~_Tp(); }
56 inline void __destroy_aux(_Tp*, const __true_type& /*_Trivial_destructor*/) {}
59 inline void _Destroy(_Tp* __pointer) {
60 #if defined (_STLP_MSVC) && (_STLP_MSVC <= 1010)
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));
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));
80 # define _STLP_NEW_REDEFINE new
84 #if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
86 inline void _Construct_aux (_T1* __p, const __false_type&) {
87 _STLP_PLACEMENT_NEW (__p) _T1();
91 inline void _Construct_aux (_T1* __p, const __true_type&) {
92 _STLP_PLACEMENT_NEW (__p) _T1(0);
94 #endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
97 inline void _Construct(_T1* __p) {
98 #if defined (_STLP_DEBUG_UNINITIALIZED)
99 memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
101 #if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
102 _Construct_aux (__p, _HasDefaultZeroValue(__p)._Answer() );
104 _STLP_PLACEMENT_NEW (__p) _T1();
105 #endif /* _STLP_DEF_CONST_PLCT_NEW_BUG */
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));
113 _STLP_PLACEMENT_NEW (__p) _Tp(__val);
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));
121 _STLP_PLACEMENT_NEW (__p) _T1(__val);
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));
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);
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));
139 _Move_Construct_Aux(__p, __val, _Is_POD(__p)._Answer());
142 #if defined(_STLP_NEW_REDEFINE)
143 # if defined (DEBUG_NEW)
144 # define new DEBUG_NEW
146 # undef _STLP_NEW_REDEFINE
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));
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));
169 __destroy_range_aux(_ForwardIterator, _ForwardIterator, _Tp*, const __true_type& /*_Trivial_destructor*/) {}
172 template <class _ForwardIterator, class _Tp>
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());
179 template <class _ForwardIterator>
180 inline void _Destroy_Range(_ForwardIterator __first, _ForwardIterator __last) {
181 __destroy_range(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
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*) {}
190 template <class _ForwardIterator, class _Tp>
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());
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));
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
206 inline _Tp __default_constructed_aux(_Tp*, const __false_type&) {
210 inline _Tp __default_constructed_aux(_Tp*, const __true_type&) {
215 inline _Tp __default_constructed(_Tp* __p) {
216 return __default_constructed_aux(__p, _HasDefaultZeroValue(__p)._Answer());
219 # define _STLP_DEFAULT_CONSTRUCTED(_TTp) __default_constructed((_TTp*)0)
221 # define _STLP_DEFAULT_CONSTRUCTED(_TTp) _TTp()
222 #endif /* _STLP_DEF_CONST_DEF_PARAM_BUG */
225 #if !defined (_STLP_NO_ANACHRONISMS)
226 // --------------------------------------------------
227 // Old names from the HP STL.
229 template <class _T1, class _T2>
230 inline void construct(_T1* __p, const _T2& __val) {_Param_Construct(__p, __val); }
232 inline void construct(_T1* __p) { _STLP_STD::_Construct(__p); }
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 */
241 #endif /* _STLP_INTERNAL_CONSTRUCT_H */