1 // nonstandard construct and destroy functions -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
29 * Hewlett-Packard Company
31 * Permission to use, copy, modify, distribute and sell this software
32 * and its documentation for any purpose is hereby granted without fee,
33 * provided that the above copyright notice appear in all copies and
34 * that both that copyright notice and this permission notice appear
35 * in supporting documentation. Hewlett-Packard Company makes no
36 * representations about the suitability of this software for any
37 * purpose. It is provided "as is" without express or implied warranty.
40 * Copyright (c) 1996,1997
41 * Silicon Graphics Computer Systems, Inc.
43 * Permission to use, copy, modify, distribute and sell this software
44 * and its documentation for any purpose is hereby granted without fee,
45 * provided that the above copyright notice appear in all copies and
46 * that both that copyright notice and this permission notice appear
47 * in supporting documentation. Silicon Graphics makes no
48 * representations about the suitability of this software for any
49 * purpose. It is provided "as is" without express or implied warranty.
52 /** @file stl_construct.h
53 * This is an internal header file, included by other library headers.
54 * You should not attempt to use it directly.
57 #ifndef _STL_CONSTRUCT_H
58 #define _STL_CONSTRUCT_H 1
62 _GLIBCXX_BEGIN_NAMESPACE(std)
65 * Constructs an object in existing memory by invoking an allocated
66 * object's constructor with an initializer.
68 template<typename _T1, typename _T2>
70 _Construct(_T1* __p, const _T2& __value)
72 // _GLIBCXX_RESOLVE_LIB_DEFECTS
73 // 402. wrong new expression in [some_]allocator::construct
74 ::new(static_cast<void*>(__p)) _T1(__value);
78 * Destroy the object pointed to by a pointer type.
80 template<typename _Tp>
82 _Destroy(_Tp* __pointer)
83 { __pointer->~_Tp(); }
88 template<typename _ForwardIterator>
90 __destroy(_ForwardIterator __first, _ForwardIterator __last)
92 for (; __first != __last; ++__first)
93 std::_Destroy(&*__first);
98 struct _Destroy_aux<true>
100 template<typename _ForwardIterator>
102 __destroy(_ForwardIterator, _ForwardIterator) { }
106 * Destroy a range of objects. If the value_type of the object has
107 * a trivial destructor, the compiler should optimize all of this
108 * away, otherwise the objects' destructors must be invoked.
110 template<typename _ForwardIterator>
112 _Destroy(_ForwardIterator __first, _ForwardIterator __last)
114 typedef typename iterator_traits<_ForwardIterator>::value_type
116 std::_Destroy_aux<__has_trivial_destructor(_Value_type)>::
117 __destroy(__first, __last);
121 * Destroy a range of objects using the supplied allocator. For
122 * nondefault allocators we do not optimize away invocation of
123 * destroy() even if _Tp has a trivial destructor.
126 template <typename _Tp> class allocator;
128 template<typename _ForwardIterator, typename _Allocator>
130 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
133 for (; __first != __last; ++__first)
134 __alloc.destroy(&*__first);
137 template<typename _ForwardIterator, typename _Tp>
139 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
142 _Destroy(__first, __last);
145 _GLIBCXX_END_NAMESPACE
147 #endif /* _STL_CONSTRUCT_H */