xref: /haiku/headers/cpp/stl_construct.h (revision 2beda3bb5be8191b672688bed7ddcadd2b17dc41)
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.
40 
41 template <class _Tp>
42 inline void destroy(_Tp* __pointer) {
43   __pointer->~_Tp();
44 }
45 
46 template <class _T1, class _T2>
47 inline void construct(_T1* __p, const _T2& __value) {
48   new (__p) _T1(__value);
49 }
50 
51 template <class _T1>
52 inline void construct(_T1* __p) {
53   new (__p) _T1();
54 }
55 
56 template <class _ForwardIterator>
57 inline void
58 __destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type)
59 {
60   for ( ; __first != __last; ++__first)
61     destroy(&*__first);
62 }
63 
64 template <class _ForwardIterator>
65 inline void __destroy_aux(_ForwardIterator, _ForwardIterator, __true_type) {}
66 
67 template <class _ForwardIterator, class _Tp>
68 inline void
69 __destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*)
70 {
71   typedef typename __type_traits<_Tp>::has_trivial_destructor
72           _Trivial_destructor;
73   __destroy_aux(__first, __last, _Trivial_destructor());
74 }
75 
76 template <class _ForwardIterator>
77 inline void destroy(_ForwardIterator __first, _ForwardIterator __last) {
78   __destroy(__first, __last, __VALUE_TYPE(__first));
79 }
80 
81 inline void destroy(char*, char*) {}
82 inline void destroy(wchar_t*, wchar_t*) {}
83 
84 __STL_END_NAMESPACE
85 
86 #endif /* __SGI_STL_INTERNAL_CONSTRUCT_H */
87 
88 // Local Variables:
89 // mode:C++
90 // End:
91