__type_traits (Traits thought)--extraction type

Source: Internet
Author: User
Tags traits

//type_traits.h----applied to STL interiors, not normalized content//Similarly, the use of objects to make exceptionsstruct__true_type {};struct__false_type {};//Design Extract MachineTemplate <classType>struct__type_traits {typedef __true_type This_dummy_member_must_be_first; /*Do not remove the this member. It informs a compiler which automatically specializes __type_traits that this __ Type_traits template is special. It just makes sure that things work if an implementation is using a template cal Led __type_traits for something unrelated. */   /*The following restrictions should is observed for the sake of compilers which automatically produce type Specifi C Specializations of this class:-Reorder the below if you wish-you may remove Any of the members below if you wish-you must don't rename members without making the corresponding NA Me change in the compiler-members you add would be treated like regular members unless you add the AP Propriate support in the compiler. */typedef __false_type Has_trivial_default_constructor;//whether the default constructor---False means taking a non-fast waytypedef __false_type Has_trivial_copy_constructor;//whether to copy the constructor-----need to use Construtor,destructortypedef __false_type Has_trivial_assignment_operator;//whether to allocate spatial functions---instead of malloc,memcpytypedef __false_type Has_trivial_destructor;//whether to unregister a functiontypedef __false_type IS_POD_TYPE;//whether traditional processing};//Special Example---have taken a quick way to do the operation, copy, assign value__stl_template_nullstruct__type_traits<Char>{typedef __true_type has_trivial_default_constructor;   typedef __true_type Has_trivial_copy_constructor;   typedef __true_type Has_trivial_assignment_operator;   typedef __true_type Has_trivial_destructor; typedef __true_type Is_pod_type;};//The special versions are://Char, signed char,unsigned char,short,unsigned Short//int,unsigned int,long,unsigned Long,float,double,long Double//t*, char*,signed char*,unsigned char*//-------------------------------------------------------------------------------------------------------//stl_uninitialized.h File Introduction to global functions//Uninitialized_fill Function--assignment function, initializing iterator interval valueTemplate <classForwardIterator,classSize,classT>inline ForwardIterator uninitialized_fill_n (forwarditerator First, Size N, Constt&x) {return__uninitialized_fill_n (First, n, X, Value_type (first));}//////the specific implementation function is __uninitialized_fill_nTemplate <classForwardIterator,classSize,classTclassT1>inline ForwardIterator __uninitialized_fill_n (forwarditerator First, Size N, Constt& x, t1*) {typedef typename __type_traits<t1>::is_pod_type is_pod;//You can see if you have a special version, you use it, you don't use generalization//generalization will return __false_type is a kind of security insurance processing, called the constructor and the like;//The __true_type is a highly efficient process because it indicates that the type T1 has a copy construct, a default construct, and a function of allocating space .  return__uninitialized_fill_n_aux (First, n, X, Is_pod ());//the type object is used here to determine which template to invoke at compile time}//for the treatment of __true_typeTemplate <classForwardIterator,classSize,classT>inline Forwarditerator__uninitialized_fill_n_aux (forwarditerator first, Size N,Constt&x, __true_type) {  returnFill_n (First, n, x);}//This function is implemented in the Stl_algobase.h file. Template <classOutputiterator,classSize,classT>outputiterator Fill_n (outputiterator First, Size N,Constt&value) {   for(; n >0; --n, + +First )*first = value;//is a process of assignment, and obviously this can be delivered to the system to process  returnFirst ;}//for the treatment of __false_typeTemplate <classForwardIterator,classSize,classT>Forwarditerator__uninitialized_fill_n_aux (forwarditerator First, Size N,Constt&x, __false_type) {ForwardIterator cur=First ; __stl_try {//It's TYR's macro.     for(; n >0; --n, + +cur) construct (&*cur, x);//This is the construct function that requires a human call to the system, in the Stl_construct.h file    returncur; }  //if not fully successful, release all previous successes__stl_unwind (Destroy (first, cur));//#define __STL_UNWIND (action) catch (...) {action; throw;}}//////the specific implementation function is Uninitialized_fill//Template <classForwardIterator,classT>inlinevoidUninitialized_fill (forwarditerator first, ForwardIterator last,Constt&x) {__uninitialized_fill (First, last, X, Value_type (first));} Template<classForwardIterator,classTclassT1>inlinevoid__uninitialized_fill (forwarditerator first, ForwardIterator last,Constt& x, t1*) {typedef typename __type_traits<T1>:: Is_pod_type is_pod;                   __uninitialized_fill_aux (First, last, X, Is_pod ()); }//trueTemplate <classForwardIterator,classT>inlinevoid__uninitialized_fill_aux (forwarditerator first, ForwardIterator last,Constt&x, __true_type) {Fill (First, last, x);}//This function is implemented in the Stl_algobase.h file.Template <classForwardIterator,classT>voidFill (forwarditerator First, ForwardIterator last,Constt&value) {   for(; First! = last; + +)First )*first =value;}//falseTemplate <classForwardIterator,classT>void__uninitialized_fill_aux (forwarditerator first, ForwardIterator last,Constt&x, __false_type) {ForwardIterator cur=First ; __stl_try { for(; cur! = last; + +)cur) construct (&*cur, x); } __stl_unwind (Destroy (first, cur));}//////the specific implementation function is Uninitialized_copy////GeneralizationTemplate <classInputiterator,classForwarditerator>inline ForwardIterator uninitialized_copy (inputiterator First, Inputiterator last, Forwarditerat or result) {return__uninitialized_copy (First, last, result, value_type (Result));}//Special ofInlineChar* Uninitialized_copy (Const Char* First,Const Char*Last ,Char*result) {Memmove (result, first, last-First ); returnResult + (last-First );}//Special ofInline wchar_t* uninitialized_copy (Constwchar_t* First,Constwchar_t*Last , wchar_t.*result) {Memmove (result, first,sizeof(wchar_t) * (Last-First )); returnResult + (last-First );} Template<classInputiterator,classForwardIterator,classT>inline Forwarditerator__uninitialized_copy (inputiterator first, Inputiterator last, Forwarditerato R result, T*) {typedef typename __type_traits<T>:: Is_pod_type is_pod; return__uninitialized_copy_aux (First, last, result, is_pod ());}//trueTemplate <classInputiterator,classForwarditerator>inline ForwardIterator __uninitialized_copy_aux (inputiterator First, Inputiterator last, Forwa Rditerator result, __true_type) {returnCopy (first, last, result);//implemented in Stl_algobase.h}//falseTemplate <classInputiterator,classForwarditerator>ForwardIterator __uninitialized_copy_aux (inputiterator First, Inputiterator last, Forwarditera Tor result, __false_type) {forwarditerator cur=result; __stl_try { for(; First! = last; ++first, + +)cur) construct (&*cur, *First ); returncur; } __stl_unwind (Destroy (result, cur));}

__type_traits (Traits thought)--extraction type

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.