deque
Category:containers Componenttype:type
Description
Adeque[1]isverymuchlikeavector:likevector,itisasequencethatsupportsrandomaccesstoelements,constanttimeinsertionandremovalofelementsattheendofthesequence,andlineartimeinsertionandremovalofelementsinthemiddle.
Themainwayinwhichdequediffersfromvectoristhatdequealsosupportsconstanttimeinsertionandremovalofelementsatthebeginningofthesequence[2].Additionally,dequedoesnothaveanymemberfunctionsanalogoustovector'scapacity()andreserve(),anddoesnotprovideanyoftheguaranteesoniteratorvaliditythatareassociatedwiththosememberfunctions.[3]
Example
dequeQ;Q.push_back(3);Q.push_front(1);Q.insert(Q.begin()+1,2);Q[2]=0;copy(Q.begin(),Q.end(),ostream_iterator(cout,""));//Thevaluesthatareprintedare120
Definition
Definedinthestandardheaderdeque,andinthenonstandardbackwardcompatibilityheaderdeque.h.
Templateparameters
Parameter Description DefaultT Thedeque'svaluetype:thetypeofobjectthatisstoredinthedeque. Alloc Thedeque'sallocator,usedforallinternalmemorymanagement. alloc
Modelof
Randomaccesscontainer,Frontinsertionsequence,Backinsertionsequence.
Typerequirements
None,exceptforthoseimposedbytherequirementsofRandomaccesscontainer,Frontinsertionsequence,andBackinsertionsequence.
Publicbaseclasses
None.
Members
Member Wheredefined Description
value_type Container Thetypeofobject,T,storedinthedeque.
pointer Container PointertoT.reference Container ReferencetoTconst_reference Container ConstreferencetoTsize_type Container Anunsignedintegraltype.difference_type Container Asignedintegraltype.iterator Container Iteratorusedtoiteratethroughadeque.const_iterator Container Constiteratorusedtoiteratethrougha
deque.reverse_iterator Reversible
ContainerIteratorusedtoiteratebackwardsthroughadeque.
const_reverse_iterator ReversibleContainer
Constiteratorusedtoiteratebackwardsthroughadeque.
iteratorbegin() Container Returnsaniteratorpointingtothebeginningofthedeque.
iteratorend() Container Returnsaniteratorpointingtotheendofthedeque.
const_iteratorbegin()const Container Returnsaconst_iteratorpointingtothebeginningofthedeque.
const_iteratorend()const Container Returnsaconst_iteratorpointingtotheendofthedeque.
reverse_iteratorrbegin() ReversibleContainer
Returnsareverse_iteratorpointingtothebeginningofthereverseddeque.
reverse_iteratorrend() ReversibleContainer
Returnsareverse_iteratorpointingtotheendofthereverseddeque.
const_reverse_iteratorrbegin()const ReversibleContainer
Returnsaconst_reverse_iteratorpointingtothebeginningofthereverseddeque.
const_reverse_iteratorrend()const Reversible Returnsaconst_reverse_iterator
Container pointingtotheendofthereverseddeque.
size_typesize()const Container Returnsthesizeofthedeque.size_typemax_size()const Container Returnsthelargestpossiblesizeofthe
deque.boolempty()const Container trueifthedeque'ssizeis0.referenceoperator[](size_typen) Random
AccessContainer
Returnsthen'thelement.
const_referenceoperator[](size_typen)const RandomAccessContainer
Returnsthen'thelement.
deque() Container Createsanemptydeque.deque(size_typen) Sequence Createsadequewithnelements.deque(size_typen,constT&t) Sequence Createsadequewithncopiesoft.deque(constdeque&) Container Thecopyconstructor.templatedeque(InputIteratorf,InputIteratorl)[4]
Sequence Createsadequewithacopyofarange.
~deque() Container Thedestructor.deque&operator=(constdeque&) Container Theassignmentoperatorreferencefront() Front
InsertionSequence
Returnsthefirstelement.
const_referencefront()const FrontInsertionSequence
Returnsthefirstelement.
referenceback() BackInsertionSequence
Returnsthelastelement.
const_referenceback()const BackInsertionSequence
Returnsthelastelement.
voidpush_front(constT&) FrontInsertionSequence
Insertsanewelementatthebeginning.
voidpush_back(constT&) BackInsertionSequence
Insertsanewelementattheend.
voidpop_front() FrontInsertionSequence
Removesthefirstelement.
voidpop_back() BackInsertion
Removesthelastelement.
Sequencevoidswap(deque&) Container Swapsthecontentsoftwodeques.iteratorinsert(iteratorpos,constT&x)
Sequence Insertsxbeforepos.
templatevoidinsert(iteratorpos,InputIteratorf,InputIteratorl)[4]
Sequence Insertstherange[f,l)beforepos.
voidinsert(iteratorpos,size_typen,constT&x)
Sequence Insertsncopiesofxbeforepos.
iteratorerase(iteratorpos) Sequence Erasestheelementatpositionpos.iteratorerase(iteratorfirst,iteratorlast) Sequence Erasestherange[first,last)voidclear() Sequence Erasesalloftheelements.voidresize(n,t=T()) Sequence Insertsoreraseselementsattheend
suchthatthesizebecomesn.booloperator==(constdeque&,constdeque&)
ForwardContainer
Teststwodequesforequality.Thisisaglobalfunction,notamemberfunction.
booloperator
Seealso
vector,list,slist
STLMainPage
ContactUs|SiteMap|Trademarks|Privacy|UsingthissitemeansyouacceptitsTermsofUseCopyright20092014SiliconGraphicsInternational.Allrightsreserved.