// Filename: stl_construct.h // comment by: Cream // E-mail: mdl2009@vip.qq.com // blog: http://blog.csdn.net/mdl13412/*** copyright (c) 1994 * Hewlett-Packard Company ** permission to use, copy, modify, distribute and submit this software * and its documentation for any purpose is hereby granted without plugin, * provided that the above copyright notice appear in all copies and * that both that copyright Notice and this permission notice appear * in supporting documentation. hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. it is provided "as is" without express or implied warranty. * ** copyright (c) 1996,1997 * Silicon Graphics Computer Systems, Inc. ** permission to use, copy, modify, distribute and perform this software * and its distribution E Ntation for any purpose is hereby granted without done, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. silicon Graphics makes no * representations about the suitability of this software for any * purpose. it is provided "as is" without express or implied warranty. * // * Note: This Is an internal header file, encoded ded by other STL headers. * You shoshould not attempt to use it directly. */# ifndef _ sgi_stl_internal_construct_h # DEFINE _ sgi_stl_internal_construct_h # include <New. h> // The prototype _ stl_begin_namespace of the placement new is required. // call the Member's destructor. The type must be non-trivial destructortemplate <class T> inline void destroy (T * pointer) {pointer-> ~ T ();} // use placement new to construct an object on the allocated memory // if you are not familiar with placement new, please refer to // http://msdn.microsoft.com/en-us/library/kewsb8ba.aspx// http://blogs.msdn.com/ B /jaredpar/archive/// 2007/10/16/c-new-operator-and-placement-new.aspxtemplate <class T1, class T2> inline void construct (T1 * P, const T2 & Value) {New (P) t1 (value);} // analyzes a group of objects, used to have non-trivial destructortemplate <class forwarditerator> inline void _ destroy_au X (forwarditerator first, forwarditerator last, _ false_type) {for (; first <last; ++ first) destroy (& * First );} // if there is no non-trivial destructor type, use this function template <class forwarditerator> inline void _ destroy_aux (forwarditerator, forwarditerator, _ true_type) {}// use the traits technology to determine whether there is a non-trivial destructor for the type, and then call different function templates <class forwarditerator, class T> inline void _ destroy (forwarditerator first, f Orwarditerator last, T *) {typedef typename _ type_traits <t>: inclutrivial_destructor; _ destroy_aux (first, last, trivial_destructor ());} //////////////////////////////////////// //////////////////////////////////////// // destroy a group of objects ///////////////////////////////// //////////////////////////////////////// /////// char * special version // ---------- destroy no destructor // | // destroy (first, last )-------- ------------------ Special // | General ------------- destroy does not perform structure analysis // | wchar_t * special version // unique // call _ destroy (first, last, value_type (first); // based on whether trivial destructor is available for function forwarding // | ---------------- has trivial destructor? // | // --------------------------------------------- // No | Yes // | // commandid // _ destroy_aux (..., _ true_type) _ destroy_aux (..., _ false_type) // you do not need to perform the Destructor for (; first <last; ++ first) // destroy (& * First ); //////////////////////////////////////// //////////////////////////////////////// template <class forwarditerator> inline void destroy (forwarditerator first, forwarditerator last) {_ destroy (first, last, value_type (first);} // special version inline void destroy (char *, char *) {} inline void destroy (wchar_t *, wchar_t *) {}__ stl_end_namespace # endif/* _ sgi_stl_internal_construct_h * // local variables: // mode: c ++ // end: