home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _construct.h < prev    next >
C/C++ Source or Header  |  2002-02-02  |  4KB  |  151 lines

  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_CSTRING)
  34. # include <cstring>
  35. # endif
  36.  
  37. # ifndef _STLP_NEW_HEADER
  38. #  include <new>
  39. # endif
  40.  
  41.  
  42. #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
  43. # include <stl/_iterator_base.h>
  44. #endif
  45.  
  46. _STLP_BEGIN_NAMESPACE
  47.  
  48. # ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
  49. template <class _Tp>
  50. inline void __destroy_aux(_Tp* __pointer, const __false_type&) { __pointer->~_Tp(); }
  51. template <class _Tp>
  52. inline void __destroy_aux(_Tp* __pointer, const __true_type&) {}
  53. # endif
  54.  
  55. template <class _Tp>
  56. inline void _Destroy(_Tp* __pointer) {
  57. # if _MSC_VER >= 1010
  58.   __pointer;
  59. # endif    // _MSC_VER >= 1000
  60. # ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
  61.   typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
  62.   __destroy_aux(__pointer, _Trivial_destructor());
  63. # else
  64. #  if ( defined (__BORLANDC__) && ( __BORLANDC__ < 0x500 ) )
  65.     __pointer->_Tp::~_Tp();
  66. #  else
  67.     __pointer->~_Tp();
  68. #  endif
  69. # endif
  70. # ifdef _STLP_DEBUG_UNINITIALIZED
  71.     memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
  72. # endif
  73. }
  74.  
  75. # if defined (new)
  76. #   define _STLP_NEW_REDEFINE new
  77. #   undef new
  78. # endif 
  79.  
  80. template <class _T1, class _T2>
  81. inline void _Construct(_T1* __p, const _T2& __val) {
  82. # ifdef _STLP_DEBUG_UNINITIALIZED
  83.     memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
  84. # endif
  85.     _STLP_PLACEMENT_NEW (__p) _T1(__val);
  86. }
  87.  
  88. template <class _T1>
  89. inline void _Construct(_T1* __p) {
  90. # ifdef _STLP_DEBUG_UNINITIALIZED
  91.   memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
  92. # endif
  93.   _STLP_PLACEMENT_NEW (__p) _T1();
  94. }
  95.  
  96. # if defined(_STLP_NEW_REDEFINE)
  97. # ifdef DEBUG_NEW
  98. #  define new DEBUG_NEW
  99. # endif
  100. #  undef _STLP_NEW_REDEFINE
  101. # endif 
  102.  
  103. template <class _ForwardIterator>
  104. _STLP_INLINE_LOOP void
  105. __destroy_aux(_ForwardIterator __first, _ForwardIterator __last, const __false_type&) {
  106.   for ( ; __first != __last; ++__first)
  107.     _Destroy(&*__first);
  108. }
  109.  
  110. template <class _ForwardIterator> 
  111. inline void __destroy_aux(_ForwardIterator, _ForwardIterator, const __true_type&) {}
  112.  
  113. template <class _ForwardIterator, class _Tp>
  114. inline void 
  115. __destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*) {
  116.   typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
  117.   __destroy_aux(__first, __last, _Trivial_destructor());
  118. }
  119.  
  120. template <class _ForwardIterator>
  121. inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last) {
  122.   __destroy(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
  123. }
  124.  
  125. inline void _Destroy(char*, char*) {}
  126. # ifdef _STLP_HAS_WCHAR_T // dwa 8/15/97
  127. inline void _Destroy(wchar_t*, wchar_t*) {}
  128. inline void _Destroy(const wchar_t*, const wchar_t*) {}
  129. # endif
  130.  
  131. # ifndef _STLP_NO_ANACHRONISMS
  132. // --------------------------------------------------
  133. // Old names from the HP STL.
  134.  
  135. template <class _T1, class _T2>
  136. inline void construct(_T1* __p, const _T2& __val) {_Construct(__p, __val); }
  137. template <class _T1>
  138. inline void construct(_T1* __p) { _Construct(__p); }
  139. template <class _Tp>
  140. inline void destroy(_Tp* __pointer) {  _Destroy(__pointer); }
  141. template <class _ForwardIterator>
  142. inline void destroy(_ForwardIterator __first, _ForwardIterator __last) { _Destroy(__first, __last); }
  143. # endif
  144. _STLP_END_NAMESPACE
  145.  
  146. #endif /* _STLP_INTERNAL_CONSTRUCT_H */
  147.  
  148. // Local Variables:
  149. // mode:C++
  150. // End:
  151.