00001 // nonstandard construct and destroy functions -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 00004 // Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // You should have received a copy of the GNU General Public License along 00018 // with this library; see the file COPYING. If not, write to the Free 00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00020 // USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00031 /* 00032 * 00033 * Copyright (c) 1994 00034 * Hewlett-Packard Company 00035 * 00036 * Permission to use, copy, modify, distribute and sell this software 00037 * and its documentation for any purpose is hereby granted without fee, 00038 * provided that the above copyright notice appear in all copies and 00039 * that both that copyright notice and this permission notice appear 00040 * in supporting documentation. Hewlett-Packard Company makes no 00041 * representations about the suitability of this software for any 00042 * purpose. It is provided "as is" without express or implied warranty. 00043 * 00044 * 00045 * Copyright (c) 1996,1997 00046 * Silicon Graphics Computer Systems, Inc. 00047 * 00048 * Permission to use, copy, modify, distribute and sell this software 00049 * and its documentation for any purpose is hereby granted without fee, 00050 * provided that the above copyright notice appear in all copies and 00051 * that both that copyright notice and this permission notice appear 00052 * in supporting documentation. Silicon Graphics makes no 00053 * representations about the suitability of this software for any 00054 * purpose. It is provided "as is" without express or implied warranty. 00055 */ 00056 00057 /** @file stl_construct.h 00058 * This is an internal header file, included by other library headers. 00059 * You should not attempt to use it directly. 00060 */ 00061 00062 #ifndef _STL_CONSTRUCT_H 00063 #define _STL_CONSTRUCT_H 1 00064 00065 #include <new> 00066 00067 _GLIBCXX_BEGIN_NAMESPACE(std) 00068 00069 /** 00070 * Constructs an object in existing memory by invoking an allocated 00071 * object's constructor with an initializer. 00072 */ 00073 template<typename _T1, typename _T2> 00074 inline void 00075 _Construct(_T1* __p, const _T2& __value) 00076 { 00077 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00078 // 402. wrong new expression in [some_]allocator::construct 00079 ::new(static_cast<void*>(__p)) _T1(__value); 00080 } 00081 00082 /** 00083 * Destroy the object pointed to by a pointer type. 00084 */ 00085 template<typename _Tp> 00086 inline void 00087 _Destroy(_Tp* __pointer) 00088 { __pointer->~_Tp(); } 00089 00090 /** 00091 * Destroy a range of objects. If the value_type of the object has 00092 * a trivial destructor, the compiler should optimize all of this 00093 * away, otherwise the objects' destructors must be invoked. 00094 */ 00095 template<typename _ForwardIterator> 00096 inline void 00097 _Destroy(_ForwardIterator __first, _ForwardIterator __last) 00098 { 00099 typedef typename iterator_traits<_ForwardIterator>::value_type 00100 _Value_type; 00101 if (!__has_trivial_destructor(_Value_type)) 00102 for (; __first != __last; ++__first) 00103 std::_Destroy(&*__first); 00104 } 00105 00106 /** 00107 * Destroy a range of objects using the supplied allocator. For 00108 * nondefault allocators we do not optimize away invocation of 00109 * destroy() even if _Tp has a trivial destructor. 00110 */ 00111 00112 template <typename _Tp> class allocator; 00113 00114 template<typename _ForwardIterator, typename _Allocator> 00115 void 00116 _Destroy(_ForwardIterator __first, _ForwardIterator __last, 00117 _Allocator& __alloc) 00118 { 00119 for (; __first != __last; ++__first) 00120 __alloc.destroy(&*__first); 00121 } 00122 00123 template<typename _ForwardIterator, typename _Tp> 00124 inline void 00125 _Destroy(_ForwardIterator __first, _ForwardIterator __last, 00126 allocator<_Tp>&) 00127 { 00128 _Destroy(__first, __last); 00129 } 00130 00131 _GLIBCXX_END_NAMESPACE 00132 00133 #endif /* _STL_CONSTRUCT_H */ 00134