Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

stl_construct.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  *
00015  * Copyright (c) 1996,1997
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */
00026 
00027 /* NOTE: This is an internal header file, included by other STL headers.
00028  *   You should not attempt to use it directly.
00029  */
00030 
00031 #ifndef _CPP_BITS_STL_CONSTRUCT_H
00032 #define _CPP_BITS_STL_CONSTRUCT_H 1
00033 
00034 #include <new>
00035 
00036 namespace std
00037 {
00038 
00039 // construct and destroy.  These functions are not part of the C++ standard,
00040 // and are provided for backward compatibility with the HP STL. We also
00041 // provide internal names _Construct and _Destroy that can be used within
00042 // the library, so that standard-conforming pieces don't have to rely on
00043 // non-standard extensions.
00044 
00045 // Internal names
00046 
00047 template <class _T1, class _T2>
00048 inline void _Construct(_T1* __p, const _T2& __value) {
00049 new ((void*) __p) _T1(__value);
00050 }
00051   
00052 template <class _T1>
00053 inline void _Construct(_T1* __p) {
00054   new ((void*) __p) _T1();
00055 }
00056 
00057 template <class _Tp>
00058 inline void _Destroy(_Tp* __pointer) {
00059   __pointer->~_Tp();
00060 }
00061   
00062 template <class _ForwardIterator>
00063 void
00064 __destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type)
00065 {
00066   for ( ; __first != __last; ++__first)
00067     destroy(&*__first);
00068 }
00069 
00070 template <class _ForwardIterator> 
00071 inline void __destroy_aux(_ForwardIterator, _ForwardIterator, __true_type) {}
00072 
00073 template <class _ForwardIterator, class _Tp>
00074 inline void 
00075 __destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*)
00076 {
00077   typedef typename __type_traits<_Tp>::has_trivial_destructor
00078           _Trivial_destructor;
00079   __destroy_aux(__first, __last, _Trivial_destructor());
00080 }
00081 
00082 template <class _ForwardIterator>
00083 inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last) {
00084   __destroy(__first, __last, __value_type(__first));
00085 }
00086 
00087 inline void _Destroy(char*, char*) {}
00088 inline void _Destroy(int*, int*) {}
00089 inline void _Destroy(long*, long*) {}
00090 inline void _Destroy(float*, float*) {}
00091 inline void _Destroy(double*, double*) {}
00092 inline void _Destroy(wchar_t*, wchar_t*) {}
00093 
00094 // --------------------------------------------------
00095 // Old names from the HP STL.
00096 
00097 template <class _T1, class _T2>
00098 inline void construct(_T1* __p, const _T2& __value) {
00099   _Construct(__p, __value);
00100 }
00101 
00102 template <class _T1>
00103 inline void construct(_T1* __p) {
00104   _Construct(__p);
00105 }
00106 
00107 template <class _Tp>
00108 inline void destroy(_Tp* __pointer) {
00109   _Destroy(__pointer);
00110 }
00111 
00112 template <class _ForwardIterator>
00113 inline void destroy(_ForwardIterator __first, _ForwardIterator __last) {
00114   _Destroy(__first, __last);
00115 }
00116 
00117 } // namespace std
00118 
00119 #endif /* _CPP_BITS_STL_CONSTRUCT_H */
00120 
00121 // Local Variables:
00122 // mode:C++
00123 // End:

Generated at Tue May 1 16:28:39 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001