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
61 #include <bits/move.h>
63 _GLIBCXX_BEGIN_NAMESPACE(std)
66 * Constructs an object in existing memory by invoking an allocated
67 * object's constructor with an initializer.
69 template<typename _T1, typename _T2>
71 #ifdef __GXX_EXPERIMENTAL_CXX0X__
72 // Allow perfect forwarding
73 _Construct(_T1* __p, _T2&& __value)
75 _Construct(_T1* __p, const _T2& __value)
78 // _GLIBCXX_RESOLVE_LIB_DEFECTS
79 // 402. wrong new expression in [some_]allocator::construct
80 ::new(static_cast<void*>(__p)) _T1(_GLIBCXX_FORWARD(_T2, __value));
84 * Destroy the object pointed to by a pointer type.
86 template<typename _Tp>
88 _Destroy(_Tp* __pointer)
89 { __pointer->~_Tp(); }
94 template<typename _ForwardIterator>
96 __destroy(_ForwardIterator __first, _ForwardIterator __last)
98 for (; __first != __last; ++__first)
99 std::_Destroy(&*__first);
104 struct _Destroy_aux<true>
106 template<typename _ForwardIterator>
108 __destroy(_ForwardIterator, _ForwardIterator) { }
112 * Destroy a range of objects. If the value_type of the object has
113 * a trivial destructor, the compiler should optimize all of this
114 * away, otherwise the objects' destructors must be invoked.
116 template<typename _ForwardIterator>
118 _Destroy(_ForwardIterator __first, _ForwardIterator __last)
120 typedef typename iterator_traits<_ForwardIterator>::value_type
122 std::_Destroy_aux<__has_trivial_destructor(_Value_type)>::
123 __destroy(__first, __last);
127 * Destroy a range of objects using the supplied allocator. For
128 * nondefault allocators we do not optimize away invocation of
129 * destroy() even if _Tp has a trivial destructor.
132 template <typename _Tp> class allocator;
134 template<typename _ForwardIterator, typename _Allocator>
136 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
139 for (; __first != __last; ++__first)
140 __alloc.destroy(&*__first);
143 template<typename _ForwardIterator, typename _Tp>
145 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
148 _Destroy(__first, __last);
151 _GLIBCXX_END_NAMESPACE
153 #endif /* _STL_CONSTRUCT_H */