STL stl_construct.h

Source: Internet
Author: User

stl_construct.h//filename:stl_construct.h//Comment by: Gel Cream//e-mail: [Email protected]//Blog:http://blog.csdn.net/mdl13412/* * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software *  and its documentation for any purpose are hereby granted without fee, * provided that the above copyright notice appear in  All copies and the both that the copyright notice and this permission notice appear * in supporting documentation.  Hewlett-Packard Company makes no * representations on 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 an D Sell this software * and it documentation for any purpose be hereby granted without fee, * provided that the above copy Right notice appear in all copies and * so both that the 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 a internal header file, included by other STL headers. * Your should not attempt to use it directly. */#ifndef __sgi_stl_internal_construct_h#define__sgi_stl_internal_construct_h#include<New.h>//need a prototype of placement new__stl_begin_namespace//the destructor of the calling member requires the type to have non-trivial destructorTemplate <classT>inlinevoidDestroy (t*pointer) {pointer->~T ();}//constructs an object on an already allocated memory using placement new//If you are unfamiliar 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 <classT1,classT2>inlinevoidConstruct (t1* p,Constt2&value) {  New(p) T1 (value);}//destructors a set of objects for a non-trivial destructorTemplate <classForwarditerator>inlinevoid__destroy_aux (forwarditerator first, ForwardIterator last, __false_type) { for(First < last; + +)First ) Destroy (&*First );}//If there is no type non-trivial destructor, use this functionTemplate <classForwarditerator>inlinevoid__destroy_aux (ForwardIterator, ForwardIterator, __true_type) {}//use the traits technique to determine if the type has non-trivial destructor and then invoke a different functionTemplate <classForwardIterator,classT>inlinevoid__destroy (ForwardIterator First, ForwardIterator last, t*) {typedef typename __type_traits<T>:: Has_trivial_destructor trivial_destructor; __destroy_aux (First, Last, Trivial_destructor ());}//////////////////////////////////////////////////////////////////////////////////used to destroy a group of objects//////////////////////////////////////////////////////////////////////////////////char * Special version//----------destroy not to be destructor//                                               |//destroy (First, last)--------------------------special//                                   | |//                                   | Generalization-----------destroy not to be destructor//                                   | wchar_t * Special Version//↓//Call __destroy (first, Last, Value_type (first));//function forwarding based on whether it has trivial destructor//                                   |//|----------------has trivial destructor?//                                   |//               -------------------------------------------//No | | Yes//               | |//↓↓//__destroy_aux (..., __true_type) __destroy_aux (..., __false_type)//do not enter need to do a destructor operation for (; first < last; ++first)//destroy (&*first);////////////////////////////////////////////////////////////////////////////////Template<classForwarditerator>inlinevoidDestroy (ForwardIterator first, ForwardIterator last) {__destroy (First, Last, Value_type (first));}//Special version ofInlinevoidDestroyChar*,Char*) {}inlinevoidDestroy (wchar_t*, wchar_t*) {}__stl_end_namespace#endif/* __sgi_stl_internal_construct_h *///Local Variables://mode:c++//End:

STL stl_construct.h

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.