5
 deque<T, Alloc> Category: containers  Component type : type Description A deque [1] is very much like a vector: like vector, it is a sequence that supports random access to elements, constant time insertion and removal of elements at the end of the sequence, and linear time insertion and removal of elements in the middle. The main way in which deque differs from vector is that deque also supports constant time insertion and removal of elements at the beginning of the sequence [2]. Additionally, deque does not have any member functions analogous to vector's capacity() and reserve(), and does not provide any of the guarantees on iterator validity that are associated with those member functions. [3] Example deque<int> Q; Q.push_back(3); Q.push_front(1); Q.insert(Q.begin() + 1, 2); Q[2] = 0; copy(Q.begin(), Q.end(), ostream_iterator<int>(cout, " ")); // The values that are printed are 1 2 0 Definition Defined in the standard header deque, and in the nonstandard backward-compatibility header deque.h. Template parameters Parameter Description Default T  The deque's value type: the type of object that is stored in the deque. Alloc  The deque's allocator, used for all internal memory management.  alloc Model of Random access container , Front insertion sequence, Back insertion sequence.

deque

Embed Size (px)

DESCRIPTION

Documentatie Deque

Citation preview

  • 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.