home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / stl / stl_construct.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-08  |  3.6 KB  |  125 lines

  1. /*
  2.  *
  3.  * Copyright (c) 1994
  4.  * Hewlett-Packard Company
  5.  *
  6.  * Permission to use, copy, modify, distribute and sell this software
  7.  * and its documentation for any purpose is hereby granted without fee,
  8.  * provided that the above copyright notice appear in all copies and
  9.  * that both that copyright notice and this permission notice appear
  10.  * in supporting documentation.  Hewlett-Packard Company makes no
  11.  * representations about the suitability of this software for any
  12.  * purpose.  It is provided "as is" without express or implied warranty.
  13.  *
  14.  *
  15.  * Copyright (c) 1996,1997
  16.  * Silicon Graphics Computer Systems, Inc.
  17.  *
  18.  * Permission to use, copy, modify, distribute and sell this software
  19.  * and its documentation for any purpose is hereby granted without fee,
  20.  * provided that the above copyright notice appear in all copies and
  21.  * that both that copyright notice and this permission notice appear
  22.  * in supporting documentation.  Silicon Graphics makes no
  23.  * representations about the suitability of this software for any
  24.  * purpose.  It is provided "as is" without express or implied warranty.
  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 __SGI_STL_INTERNAL_CONSTRUCT_H
  32. #define __SGI_STL_INTERNAL_CONSTRUCT_H
  33.  
  34. #include <new.h>
  35.  
  36. __STL_BEGIN_NAMESPACE
  37.  
  38. // construct and destroy.  These functions are not part of the C++ standard,
  39. // and are provided for backward compatibility with the HP STL.  We also
  40. // provide internal names _Construct and _Destroy that can be used within
  41. // the library, so that standard-conforming pieces don't have to rely on
  42. // non-standard extensions.
  43.  
  44. // Internal names
  45.  
  46. template <class _T1, class _T2>
  47. inline void _Construct(_T1* __p, const _T2& __value) {
  48.   new ((void*) __p) _T1(__value);
  49. }
  50.  
  51. template <class _T1>
  52. inline void _Construct(_T1* __p) {
  53.   new ((void*) __p) _T1();
  54. }
  55.  
  56. template <class _Tp>
  57. inline void _Destroy(_Tp* __pointer) {
  58.   __pointer->~_Tp();
  59. }
  60.  
  61. template <class _ForwardIterator>
  62. void
  63. __destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type)
  64. {
  65.   for ( ; __first != __last; ++__first)
  66.     destroy(&*__first);
  67. }
  68.  
  69. template <class _ForwardIterator> 
  70. inline void __destroy_aux(_ForwardIterator, _ForwardIterator, __true_type) {}
  71.  
  72. template <class _ForwardIterator, class _Tp>
  73. inline void 
  74. __destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*)
  75. {
  76.   typedef typename __type_traits<_Tp>::has_trivial_destructor
  77.           _Trivial_destructor;
  78.   __destroy_aux(__first, __last, _Trivial_destructor());
  79. }
  80.  
  81. template <class _ForwardIterator>
  82. inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last) {
  83.   __destroy(__first, __last, __VALUE_TYPE(__first));
  84. }
  85.  
  86. inline void _Destroy(char*, char*) {}
  87. inline void _Destroy(int*, int*) {}
  88. inline void _Destroy(long*, long*) {}
  89. inline void _Destroy(float*, float*) {}
  90. inline void _Destroy(double*, double*) {}
  91. #ifdef __STL_HAS_WCHAR_T
  92. inline void _Destroy(wchar_t*, wchar_t*) {}
  93. #endif /* __STL_HAS_WCHAR_T */
  94.  
  95. // --------------------------------------------------
  96. // Old names from the HP STL.
  97.  
  98. template <class _T1, class _T2>
  99. inline void construct(_T1* __p, const _T2& __value) {
  100.   _Construct(__p, __value);
  101. }
  102.  
  103. template <class _T1>
  104. inline void construct(_T1* __p) {
  105.   _Construct(__p);
  106. }
  107.  
  108. template <class _Tp>
  109. inline void destroy(_Tp* __pointer) {
  110.   _Destroy(__pointer);
  111. }
  112.  
  113. template <class _ForwardIterator>
  114. inline void destroy(_ForwardIterator __first, _ForwardIterator __last) {
  115.   _Destroy(__first, __last);
  116. }
  117.  
  118. __STL_END_NAMESPACE
  119.  
  120. #endif /* __SGI_STL_INTERNAL_CONSTRUCT_H */
  121.  
  122. // Local Variables:
  123. // mode:C++
  124. // End:
  125.