侯捷stl源码剖析注释之47 listfunctiontree.docx
- 文档编号:8931077
- 上传时间:2023-02-02
- 格式:DOCX
- 页数:73
- 大小:38.72KB
侯捷stl源码剖析注释之47 listfunctiontree.docx
《侯捷stl源码剖析注释之47 listfunctiontree.docx》由会员分享,可在线阅读,更多相关《侯捷stl源码剖析注释之47 listfunctiontree.docx(73页珍藏版)》请在冰豆网上搜索。
侯捷stl源码剖析注释之47listfunctiontree
G++2.91.57,cygnus\cygwin-b20\include\g++\stl_list.h完整列表
/*
*
*Copyright(c)1994
*Hewlett-PackardCompany
*
*Permissiontouse,copy,modify,distributeandsellthissoftware
*anditsdocumentationforanypurposeisherebygrantedwithoutfee,
*providedthattheabovecopyrightnoticeappearinallcopiesand
*thatboththatcopyrightnoticeandthispermissionnoticeappear
*insupportingdocumentation.Hewlett-PackardCompanymakesno
*representationsaboutthesuitabilityofthissoftwareforany
*purpose.Itisprovided"asis"withoutexpressorimpliedwarranty.
*
*
*Copyright(c)1996,1997
*SiliconGraphicsComputerSystems,Inc.
*
*Permissiontouse,copy,modify,distributeandsellthissoftware
*anditsdocumentationforanypurposeisherebygrantedwithoutfee,
*providedthattheabovecopyrightnoticeappearinallcopiesand
*thatboththatcopyrightnoticeandthispermissionnoticeappear
*insupportingdocumentation.SiliconGraphicsmakesno
*representationsaboutthesuitabilityofthissoftwareforany
*purpose.Itisprovided"asis"withoutexpressorimpliedwarranty.
*/
/*NOTE:
Thisisaninternalheaderfile,includedbyotherSTLheaders.
*Youshouldnotattempttouseitdirectly.
*/
#ifndef__SGI_STL_INTERNAL_LIST_H
#define__SGI_STL_INTERNAL_LIST_H
__STL_BEGIN_NAMESPACE
#ifdefined(__sgi)&&!
defined(__GNUC__)&&(_MIPS_SIM!
=_MIPS_SIM_ABI32)
#pragmasetwoff1174
#endif
template
struct__list_node{
typedefvoid*void_pointer;
void_pointernext;
void_pointerprev;
Tdata;
};
template
struct__list_iterator{
typedef__list_iterator
typedef__list_iterator
typedef__list_iterator
typedefbidirectional_iterator_tagiterator_category;
typedefTvalue_type;
typedefPtrpointer;
typedefRefreference;
typedef__list_node
typedefsize_tsize_type;
typedefptrdiff_tdifference_type;
link_typenode;
__list_iterator(link_typex):
node(x){}
__list_iterator(){}
__list_iterator(constiterator&x):
node(x.node){}
booloperator==(constself&x)const{returnnode==x.node;}
booloperator!
=(constself&x)const{returnnode!
=x.node;}
referenceoperator*()const{return(*node).data;}
#ifndef__SGI_STL_NO_ARROW_OPERATOR
pointeroperator->()const{return&(operator*());}
#endif/*__SGI_STL_NO_ARROW_OPERATOR*/
self&operator++(){
node=(link_type)((*node).next);
return*this;
}
selfoperator++(int){
selftmp=*this;
++*this;
returntmp;
}
self&operator--(){
node=(link_type)((*node).prev);
return*this;
}
selfoperator--(int){
selftmp=*this;
--*this;
returntmp;
}
};
#ifndef__STL_CLASS_PARTIAL_SPECIALIZATION
template
inlinebidirectional_iterator_tag
iterator_category(const__list_iterator
returnbidirectional_iterator_tag();
}
template
inlineT*
value_type(const__list_iterator
return0;
}
template
inlineptrdiff_t*
distance_type(const__list_iterator
return0;
}
#endif/*__STL_CLASS_PARTIAL_SPECIALIZATION*/
template
classlist{
protected:
typedefvoid*void_pointer;
typedef__list_node
typedefsimple_alloc
public:
typedefTvalue_type;
typedefvalue_type*pointer;
typedefconstvalue_type*const_pointer;
typedefvalue_type&reference;
typedefconstvalue_type&const_reference;
typedeflist_node*link_type;
typedefsize_tsize_type;
typedefptrdiff_tdifference_type;
public:
typedef__list_iterator
typedef__list_iterator
#ifdef__STL_CLASS_PARTIAL_SPECIALIZATION
typedefreverse_iterator
typedefreverse_iterator
#else/*__STL_CLASS_PARTIAL_SPECIALIZATION*/
typedefreverse_bidirectional_iterator const_reference,difference_type> const_reverse_iterator; typedefreverse_bidirectional_iterator difference_type> reverse_iterator; #endif/*__STL_CLASS_PARTIAL_SPECIALIZATION*/ protected: link_typeget_node(){returnlist_node_allocator: : allocate();} voidput_node(link_typep){list_node_allocator: : deallocate(p);} link_typecreate_node(constT&x){ link_typep=get_node(); __STL_TRY{ construct(&p->data,x); } __STL_UNWIND(put_node(p)); returnp; } voiddestroy_node(link_typep){ destroy(&p->data); put_node(p); } protected: voidempty_initialize(){ node=get_node(); node->next=node; node->prev=node; } voidfill_initialize(size_typen,constT&value){ empty_initialize(); __STL_TRY{ insert(begin(),n,value); } __STL_UNWIND(clear();put_node(node)); } #ifdef__STL_MEMBER_TEMPLATES template voidrange_initialize(InputIteratorfirst,InputIteratorlast){ empty_initialize(); __STL_TRY{ insert(begin(),first,last); } __STL_UNWIND(clear();put_node(node)); } #else/*__STL_MEMBER_TEMPLATES*/ voidrange_initialize(constT*first,constT*last){ empty_initialize(); __STL_TRY{ insert(begin(),first,last); } __STL_UNWIND(clear();put_node(node)); } voidrange_initialize(const_iteratorfirst,const_iteratorlast){ empty_initialize(); __STL_TRY{ insert(begin(),first,last); } __STL_UNWIND(clear();put_node(node)); } #endif/*__STL_MEMBER_TEMPLATES*/ protected: link_typenode; public: list(){empty_initialize();} iteratorbegin(){return(link_type)((*node).next);} const_iteratorbegin()const{return(link_type)((*node).next);} iteratorend(){returnnode;} const_iteratorend()const{returnnode;} reverse_iteratorrbegin(){returnreverse_iterator(end());} const_reverse_iteratorrbegin()const{ returnconst_reverse_iterator(end()); } reverse_iteratorrend(){returnreverse_iterator(begin());} const_reverse_iteratorrend()const{ returnconst_reverse_iterator(begin()); } boolempty()const{returnnode->next==node;} size_typesize()const{ size_typeresult=0; distance(begin(),end(),result); returnresult; } size_typemax_size()const{returnsize_type(-1);} referencefront(){return*begin();} const_referencefront()const{return*begin();} referenceback(){return*(--end());} const_referenceback()const{return*(--end());} voidswap(list : swap(node,x.node);} iteratorinsert(iteratorposition,constT&x){ link_typetmp=create_node(x); tmp->next=position.node; tmp->prev=position.node->prev; (link_type(position.node->prev))->next=tmp; position.node->prev=tmp; returntmp; } iteratorinsert(iteratorposition){returninsert(position,T());} #ifdef__STL_MEMBER_TEMPLATES template voidinsert(iteratorposition,InputIteratorfirst,InputIteratorlast); #else/*__STL_MEMBER_TEMPLATES*/ voidinsert(iteratorposition,constT*first,constT*last); voidinsert(iteratorposition, const_iteratorfirst,const_iteratorlast); #endif/*__STL_MEMBER_TEMPLATES*/ voidinsert(iteratorpos,size_typen,constT&x); voidinsert(iteratorpos,intn,constT&x){ insert(pos,(size_type)n,x); } voidinsert(iteratorpos,longn,constT&x){ insert(pos,(size_type)n,x); } voidpush_front(constT&x){insert(begin(),x);} voidpush_back(constT&x){insert(end(),x);} iteratorerase(iteratorposition){ link_typenext_node=link_type(position.node->next); link_typeprev_node=link_type(position.node->prev); prev_node->next=next_node; next_node->prev=prev_node; destroy_node(position.node); returniterator(next_node); } iteratorerase(iteratorfirst,iteratorlast); voidresize(size_typenew_size,constT&x); voidresize(size_typenew_size){resize(new_size,T());} voidclear(); voidpop_front(){erase(begin());} voidpop_back(){ iteratortmp=end(); erase(--tmp); } list(size_typen,constT&value){fill_initialize(n,value);} list(intn,constT&value){fill_initialize(n,value);} list(longn,constT&value){fill_initialize(n,value);} explicitlist(size_typen){fill_initialize(n,T());} #ifdef__STL_MEMBER_TEMPLATES template list(InputIteratorfirst,InputIteratorlast){ range_initialize(first,last); } #else/*__STL_MEMBER_TEMPLATES*/ list(constT*first,constT*last){range_initialize(first,last);} list(const_iteratorfirst,const_iteratorlast){ range_initialize(first,last); } #endif/*__STL_MEMBER_TEMPLATES*/ list(constlist range_initialize(x.begin(),x.end()); } ~list(){ clear(); put_node(node); } list protected: voidtransfer(iteratorposition,iteratorfirst,iteratorlast){ if(position! =last){ (*(link_type((*last.node).prev))).next=position.node; (*(link_type((*first.node).prev))).next=last.node; (*(link_type((*position.node).prev))).next=first.node; link_typetmp=link_type((*position.node).prev); (*position.node).prev=(*last.node).prev; (*last.node).prev=(*first.node).prev; (*first.node).prev=tmp; } } public: voidsplice(iteratorposition,list&x){ if(! x.empty()) transfer(position,x.begin(),x.end()); } voidsplice(iteratorposition,list&,iteratori){ iteratorj=i; ++j; if(position==i||position==j)return; transfer(position,i,j);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 侯捷stl源码剖析注释之47 listfunctiontree 侯捷 stl 源码 剖析 注释 47