escenciales stl

Upload: alex-madrigal

Post on 23-Feb-2018

251 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/24/2019 Escenciales Stl

    1/19

    class template

    std::pairtemplate struct pair;

    Pair of values

    This class couples together a pair of values, which may be of different types (T1and T2). The individual values can be accessed through its

    public members firstand second.

    Pairs are a particular case of tuple.

    Template parameters

    T1

    Type of member first, aliased as first_type.

    T2

    Type of member second, aliased as second_type.

    Member types

    member type definition notes

    first_type The first template parameter (T1) Type of member first.

    second_type The second template parameter (T2) Type of member second.

    Member variables

    member variable definition

    first The first value in the pair

    second The second value in the pair

    Member functions

    (constructor)

    Construct pair (public member function )

    pair::operator=

    Assign contents (public member function )

    pair::swap

    Swap contents (public member function )

    Non-member function overloads

    relational operators (pair)

    elational operators for pair (function template )

    swap (pair)

    !"changes the contents of two pairs (function template )

    get (pair)

    #et element (tuple interface) (function template )

    Non-member class specializations

    tuple_elementpair!

    Tuple element type for pair (class template speciali$ation )

    tuple_sizepair!

    Tuple traits for pair (class template speciali$ation )

    "ee also

    ma#e_pair

    Construct pair ob%ect (function template )

    piecewise_construct

    Piecewise construct constant (constant )

    function template

    std::make_pair

    http://www.cplusplus.com/tuplehttp://www.cplusplus.com/tuplehttp://www.cplusplus.com/reference/utility/pair/pair/http://www.cplusplus.com/reference/utility/pair/operator=/http://www.cplusplus.com/reference/utility/pair/swap/http://www.cplusplus.com/reference/utility/pair/operators/http://www.cplusplus.com/reference/utility/pair/swap-free/http://www.cplusplus.com/reference/utility/pair/get/http://www.cplusplus.com/reference/utility/pair/tuple_element/http://www.cplusplus.com/reference/utility/pair/tuple_size/http://www.cplusplus.com/reference/utility/make_pair/http://www.cplusplus.com/reference/utility/piecewise_construct/http://www.cplusplus.com/reference/utility/pair/pair/http://www.cplusplus.com/reference/utility/pair/operator=/http://www.cplusplus.com/reference/utility/pair/swap/http://www.cplusplus.com/reference/utility/pair/operators/http://www.cplusplus.com/reference/utility/pair/swap-free/http://www.cplusplus.com/reference/utility/pair/get/http://www.cplusplus.com/reference/utility/pair/tuple_element/http://www.cplusplus.com/reference/utility/pair/tuple_size/http://www.cplusplus.com/reference/utility/make_pair/http://www.cplusplus.com/reference/utility/piecewise_construct/http://www.cplusplus.com/tuple
  • 7/24/2019 Escenciales Stl

    2/19

    C++98

    C++

    template pair make_pair (T1 x, T2 y);

    Construct pair object

    Constructs a pairobject with its frst element set toxand its second element set toy.

    The template types can be implicitly deduced rom the arguments passed to make_pair.

    pairobjects can be constructed rom otherpairobjects containing dierent types, i the respective types are

    implicitly convertible.

    C++9

    C++!!

    The behavior o this unction template is the same as i defned as"

    1234

    template pair make_pair (T1 x, T2 y) ! return( pair(x,y) ); "

    #arameters

    x, y

    $alues or the members firstand second, respectively, o the pairobject being constructed.

    %eturn value

    & pairobject whose elements firstand secondare set toxandyrespectivelly.

    The template parameters can be implicitly deduced.

    '(ample

    1234#$%&1'

    1112131411#

    make_pair exampleinclude std**pairinclude std**cout

    intmain () ! std**pair foo; std**pair +ar;

    foo std**make_pair (1',2'); +ar std**make_pair (1'-,./.); ok* implicit con0ersion from

    pair

    std**cout

  • 7/24/2019 Escenciales Stl

    3/19

    either or both- T1or T2is an rvalue referencetype o a type supporting move semantics, its corresponding

    argument is modifed.

    '(ception saety

    The unction provides the same level o guarantees to each object as provided by the corresponding element

    constructor.

    Construct pair public member unction -

    function template

    std::$et (pair)

    lvalue (1)

    template typename tuple_element< 5, pair >**type6 7et (pair6 pr) noexcept;

    rvalue (2)

    template typename tuple_element< 5, pair >**type66 7et (pair66 pr) noexcept;

    const (3)

    template const typename tuple_element< 5, pair >**type6 7et (const pair6 pr) noexcept;

    Get element (tuple interface)

    %eturns a reerence to member firsti Iis ', or a reerence to member secondi Iis 1.

    This overload o tuples homonym unction7etis provided so that pairobjects can be treated as a tuples. /or

    that purpose, header also overloads tuple_sieand tuple_elementtypes with the appropriate

    members defned.

    Template parameters

    5

    #osition o an element in the pair, with 'identiying member first, and 1identiying member second.

    si0e1tis an unsigned integral type.

    T1, T2

    Type o the elements in the pair.

    /unction parameters

    pr

    & pairobject.

    %eturn value

    & reerence to a member o the pair.

    /or rvaluepairobjects (2), the unction returns an rvalue referenceas i for8ardwas used-.

    '(ample

    1234

    http://www.cplusplus.com/tuplehttp://www.cplusplus.com/gethttp://www.cplusplus.com/gethttp://www.cplusplus.com/pairhttp://www.cplusplus.com/tuplehttp://www.cplusplus.com/%3Cutility%3Ehttp://www.cplusplus.com/%3Cutility%3Ehttp://www.cplusplus.com/tuple_size%3Cpair%3Ehttp://www.cplusplus.com/tuple_element%3Cpair%3Ehttp://www.cplusplus.com/pairhttp://www.cplusplus.com/size_thttp://www.cplusplus.com/size_thttp://www.cplusplus.com/pairhttp://www.cplusplus.com/pairhttp://www.cplusplus.com/pairhttp://www.cplusplus.com/pairhttp://www.cplusplus.com/pairhttp://www.cplusplus.com/pairhttp://www.cplusplus.com/pairhttp://www.cplusplus.com/forwardhttp://www.cplusplus.com/tuplehttp://www.cplusplus.com/gethttp://www.cplusplus.com/pairhttp://www.cplusplus.com/tuplehttp://www.cplusplus.com/%3Cutility%3Ehttp://www.cplusplus.com/tuple_size%3Cpair%3Ehttp://www.cplusplus.com/tuple_element%3Cpair%3Ehttp://www.cplusplus.com/pairhttp://www.cplusplus.com/size_thttp://www.cplusplus.com/pairhttp://www.cplusplus.com/pairhttp://www.cplusplus.com/pairhttp://www.cplusplus.com/pairhttp://www.cplusplus.com/forward
  • 7/24/2019 Escenciales Stl

    4/19

    #$%&1'11121314

    accessin7 pairs 8it 7etinclude std**pair, std**7et

    include std**cout

    intmain () ! std**pair foo (1',.x.);

    std**7et

  • 7/24/2019 Escenciales Stl

    5/19

    header

    %list&

    List header

    2eader that defnes the listcontainer class"

    Classes

    list

    3ist class template -

    /unctions

    begin

    terator to beginning unction template -

    end

    terator to end unction template -

    function template

    std::begin

    C++

    C++'

    container (1) template auto +e7in (:ontainer6 cont) > decltype(cont-+e7in());

    template auto +e7in (const :ontainer6 cont) > declty(cont-+e7in());

    array (2) template T= +e7in (T(6arr)?);

    Iterator to beginning

    eturns an iterator pointing to the first element in the se&uence'

    (1) Container

    The function returns cont-+e7in().

    (2) Array

    The function returns the array-to-pointer conversionof its argument.

    f the se&uence is empty, the returned value shall not be dereferenced.

    These function templates are defined in multiple headers' !ach of these headers includes the generic templates for all container and array

    types and not simply a specific overload. The headers

    are',,,,,map,,,,,and .

    Conversely,+e7inis overloaded (with a different definition) in headersand .

    $arameters

    http://www.cplusplus.com/listhttp://www.cplusplus.com/reference/list/list/http://www.cplusplus.com/reference/iterator/begin/http://www.cplusplus.com/reference/iterator/end/http://switch1.select%281%29/http://switch1.select%282%29/http://www.cplusplus.com/%3Citerator%3Ehttp://www.cplusplus.com/%3Citerator%3Ehttp://www.cplusplus.com/%3Citerator%3Ehttp://www.cplusplus.com/%3Carray%3Ehttp://www.cplusplus.com/%3Cdeque%3Ehttp://www.cplusplus.com/%3Cdeque%3Ehttp://www.cplusplus.com/%3Cforward_list%3Ehttp://www.cplusplus.com/%3Cforward_list%3Ehttp://www.cplusplus.com/%3Clist%3Ehttp://www.cplusplus.com/%3Clist%3Ehttp://www.cplusplus.com/%3Cmap%3Ehttp://www.cplusplus.com/%3Cmap%3Ehttp://www.cplusplus.com/%3Cmap%3Ehttp://www.cplusplus.com/%3Cregex%3Ehttp://www.cplusplus.com/%3Cregex%3Ehttp://www.cplusplus.com/%3Cset%3Ehttp://www.cplusplus.com/%3Cset%3Ehttp://www.cplusplus.com/%3Cset%3Ehttp://www.cplusplus.com/%3Cstring%3Ehttp://www.cplusplus.com/%3Cunordered_map%3Ehttp://www.cplusplus.com/%3Cunordered_map%3Ehttp://www.cplusplus.com/%3Cunordered_map%3Ehttp://www.cplusplus.com/%3Cunordered_set%3Ehttp://www.cplusplus.com/%3Cunordered_set%3Ehttp://www.cplusplus.com/%3Cunordered_set%3Ehttp://www.cplusplus.com/%3Cunordered_set%3Ehttp://www.cplusplus.com/%3Cvector%3Ehttp://www.cplusplus.com/beginhttp://www.cplusplus.com/beginhttp://www.cplusplus.com/beginhttp://www.cplusplus.com/%3Cinitializer_list%3Ehttp://www.cplusplus.com/%3Cinitializer_list%3Ehttp://www.cplusplus.com/%3Cinitializer_list%3Ehttp://www.cplusplus.com/%3Cvalarray%3Ehttp://www.cplusplus.com/listhttp://www.cplusplus.com/reference/list/list/http://www.cplusplus.com/reference/iterator/begin/http://www.cplusplus.com/reference/iterator/end/http://switch1.select%281%29/http://switch1.select%282%29/http://www.cplusplus.com/%3Citerator%3Ehttp://www.cplusplus.com/%3Carray%3Ehttp://www.cplusplus.com/%3Cdeque%3Ehttp://www.cplusplus.com/%3Cforward_list%3Ehttp://www.cplusplus.com/%3Clist%3Ehttp://www.cplusplus.com/%3Cmap%3Ehttp://www.cplusplus.com/%3Cregex%3Ehttp://www.cplusplus.com/%3Cset%3Ehttp://www.cplusplus.com/%3Cstring%3Ehttp://www.cplusplus.com/%3Cunordered_map%3Ehttp://www.cplusplus.com/%3Cunordered_set%3Ehttp://www.cplusplus.com/%3Cunordered_set%3Ehttp://www.cplusplus.com/%3Cvector%3Ehttp://www.cplusplus.com/beginhttp://www.cplusplus.com/%3Cinitializer_list%3Ehttp://www.cplusplus.com/%3Cvalarray%3E
  • 7/24/2019 Escenciales Stl

    6/19

    cont

    An ob%ect of a class type for which member +e7inis defined.

    arr

    An array.

    %eturn &alue

    or (1), the same as returned by cont-+e7in().

    or (2), a pointer to the first element in the array.

    'ample

    1234#$%&1'111213

    1411#1$1%1&2'

    std**+e7in std**end exampleinclude std**coutinclude std**0ector, std**+e7in, std**end

    intmain () ! intfoo? !1',2',3',4','"; std**0ector +ar;

    iterate foo* insertin7 into +ar for(autoit std**+e7in(foo); it@std**end(foo); AAit) +ar-pus_+ack(=it);

    iterate +ar* print contents*

    std**cout

  • 7/24/2019 Escenciales Stl

    7/19

    (1) Container

    The function returns cont-end().

    (2) Array

    The function returns arrA.

    f the se&uence is empty, the returned value compares e&ual to the one returned by+e7inwith the same argument.

    These function templates are defined in multiple headers' !ach of these headers includes the generic templates for all container and arraytypes and not simply a specific overload. The headers

    are',,,,,map,,,,,and .

    Conversely,endis overloaded (with a different definition) in headersand.

    $arameters

    cont

    An ob%ect of a class type for which member endis defined.

    arr

    An array.

    %eturn &alue

    or (1), the same as returned by cont-end().

    or (2), a pointer to the element that would follow the last element in the array.

    'ample

    1234#$%&1'11

    12131411#1$1%1&2'

    std**+e7in std**end exampleinclude std**coutinclude std**0ector, std**+e7in, std**end

    intmain () ! intfoo? !1',2',3',4','"; std**0ector +ar;

    iterate foo* insertin7 into +ar for(autoit std**+e7in(foo); it@std**end(foo); AAit) +ar-pus_+ack(=it);

    iterate +ar* print contents* std**cout

  • 7/24/2019 Escenciales Stl

    8/19

    class template

    std::queuetemplate class 9ueue;

    I! queue

    *ueues are a type of container adaptor, specifically designed to operate in a * conte"t (firstin firstout), where elements are inserted into

    one end of the container and e"tracted from the other.

    *ueues are implemented as containers adaptors, which are classes that use an encapsulated ob%ect of a specific container class as

    its underlying container, providing a specific set of member functions to access its elements. !lements arepushedinto the "back"of the

    specific container andpoppedfrom its "front".

    The underlying container may be one of the standard container class template or some other specifically designed container class. Thisunderlying container shall support at least the following operations'

    empty

    sie

    front

    +ack

    pus_+ack

    pop_front

    The standard container classesde&ueandlistfulfill these re&uirements. -y default, if no container class is specified for a

    particular 9ueueclass instantiation, the standard containerde&ueis used.

    Template parameters

    T

    Type of the elements.Aliased as member type 9ueue**0alue_type.

    :ontainer

    Type of the internal underlying containerob%ect where the elements are stored.

    ts 0alue_typeshall be T.

    Aliased as member type 9ueue**container_type.

    Member types

    C/0

    C11

    member type definition notes

    0alue_type The first template parameter (T) Type of the elements

    container_type The second template parameter (:ontainer) Type of the underlying container

    sie_type an unsi$ned inte$ral type usually the same as si$e2t

    http://www.cplusplus.com/dequehttp://www.cplusplus.com/dequehttp://www.cplusplus.com/listhttp://www.cplusplus.com/listhttp://www.cplusplus.com/listhttp://www.cplusplus.com/dequehttp://www.cplusplus.com/dequehttp://www.cplusplus.com/dequehttp://switch1.select%281%29/http://switch1.select%282%29/http://www.cplusplus.com/size_thttp://www.cplusplus.com/dequehttp://www.cplusplus.com/listhttp://www.cplusplus.com/dequehttp://switch1.select%281%29/http://switch1.select%282%29/http://www.cplusplus.com/size_t
  • 7/24/2019 Escenciales Stl

    9/19

    Member functions

    (constructor)

    Construct &ueue (public member function )

    empty

    Test whether container is empty (public member function )

    size

    eturn si$e (public member function )

    front

    Access ne"t element (public member function )

    bac#Access last element (public member function )

    pus+

    nsert element (public member function )

    emplace

    Construct and insert element (public member function )

    pop

    emove ne"t element (public member function )

    swap

    Swap contents (public member function )

    Non-member function overloads

    relational operators

    elational operators for &ueue (function )

    swap (*ueue)

    !"change contents of &ueues (public member function )

    Non-member class specializations

    uses_allocator*ueue!

    3ses allocator for &ueue (class template )

    std::stac"template class stack;

    LI! stac"

    Stac4s are a type of container adaptor, specifically designed to operate in a 5* conte"t (lastin firstout), where elements are inserted ande"tracted only from one end of the container.

    stac#s are implemented as containers adaptors, which are classes that use an encapsulated ob%ect of a specific container class as

    its underlying container, providing a specific set of member functions to access its elements. !lements arepushed6poppedfrom the "back"ofthe specific container, which is 4nown as the topof the stac4.

    The underlying container may be any of the standard container class templates or some other specifically designed container class. Thecontainer shall support the following operations'

    empty

    sie

    +ack

    pus_+ack

    pop_+ack

    The standard container classesvector,de&ueandlistfulfill these re&uirements. -y default, if no container class is specified for a

    particular stackclass instantiation, the standard containerde&ueis used.

    http://www.cplusplus.com/reference/queue/queue/queue/http://www.cplusplus.com/reference/queue/queue/empty/http://www.cplusplus.com/reference/queue/queue/size/http://www.cplusplus.com/reference/queue/queue/front/http://www.cplusplus.com/reference/queue/queue/back/http://www.cplusplus.com/reference/queue/queue/push/http://www.cplusplus.com/reference/queue/queue/emplace/http://www.cplusplus.com/reference/queue/queue/pop/http://www.cplusplus.com/reference/queue/queue/swap/http://www.cplusplus.com/reference/queue/queue/operators/http://www.cplusplus.com/reference/queue/queue/swap-free/http://www.cplusplus.com/reference/queue/queue/uses_allocator/http://www.cplusplus.com/vectorhttp://www.cplusplus.com/vectorhttp://www.cplusplus.com/dequehttp://www.cplusplus.com/dequehttp://www.cplusplus.com/listhttp://www.cplusplus.com/listhttp://www.cplusplus.com/listhttp://www.cplusplus.com/dequehttp://www.cplusplus.com/dequehttp://www.cplusplus.com/dequehttp://www.cplusplus.com/reference/queue/queue/queue/http://www.cplusplus.com/reference/queue/queue/empty/http://www.cplusplus.com/reference/queue/queue/size/http://www.cplusplus.com/reference/queue/queue/front/http://www.cplusplus.com/reference/queue/queue/back/http://www.cplusplus.com/reference/queue/queue/push/http://www.cplusplus.com/reference/queue/queue/emplace/http://www.cplusplus.com/reference/queue/queue/pop/http://www.cplusplus.com/reference/queue/queue/swap/http://www.cplusplus.com/reference/queue/queue/operators/http://www.cplusplus.com/reference/queue/queue/swap-free/http://www.cplusplus.com/reference/queue/queue/uses_allocator/http://www.cplusplus.com/vectorhttp://www.cplusplus.com/dequehttp://www.cplusplus.com/listhttp://www.cplusplus.com/deque
  • 7/24/2019 Escenciales Stl

    10/19

    Template parameters

    T

    Type of the elements.

    Aliased as member type stack**0alue_type.

    :ontainer

    Type of the internal underlying containerob%ect where the elements are stored.ts 0alue_typeshall be T.

    Aliased as member type stack**container_type.

    Member types

    C/0

    C11

    member type definition notes

    0alue_type The first template parameter (T) Type of the elements

    container_type The second template parameter (:ontainer) Type of the underlying container

    sie_type an unsi$ned inte$ral type usually the same as si$e2t

    Member functions

    (constructor)

    Construct stac4 (public member function )

    empty

    Test whether container is empty (public member function )

    size

    eturn si$e (public member function )

    top

    Access ne"t element (public member function )

    pus+

    nsert element (public member function )emplace

    Construct and insert element (public member function )

    pop

    emove top element (public member function )

    swap

    Swap contents (public member function )

    Non-member function overloads

    relational operators

    elational operators for stac4 (function )

    swap (stac#)

    !"change contents of stac4s (public member function )

    Non-member class specializations

    uses_allocatorstac#!

    3ses allocator for stac4 (class template )

    http://switch1.select%281%29/http://switch1.select%282%29/http://www.cplusplus.com/size_thttp://www.cplusplus.com/reference/stack/stack/stack/http://www.cplusplus.com/reference/stack/stack/empty/http://www.cplusplus.com/reference/stack/stack/size/http://www.cplusplus.com/reference/stack/stack/top/http://www.cplusplus.com/reference/stack/stack/push/http://www.cplusplus.com/reference/stack/stack/emplace/http://www.cplusplus.com/reference/stack/stack/pop/http://www.cplusplus.com/reference/stack/stack/swap/http://www.cplusplus.com/reference/stack/stack/operators/http://www.cplusplus.com/reference/stack/stack/swap-free/http://www.cplusplus.com/reference/stack/stack/uses_allocator/http://switch1.select%281%29/http://switch1.select%282%29/http://www.cplusplus.com/size_thttp://www.cplusplus.com/reference/stack/stack/stack/http://www.cplusplus.com/reference/stack/stack/empty/http://www.cplusplus.com/reference/stack/stack/size/http://www.cplusplus.com/reference/stack/stack/top/http://www.cplusplus.com/reference/stack/stack/push/http://www.cplusplus.com/reference/stack/stack/emplace/http://www.cplusplus.com/reference/stack/stack/pop/http://www.cplusplus.com/reference/stack/stack/swap/http://www.cplusplus.com/reference/stack/stack/operators/http://www.cplusplus.com/reference/stack/stack/swap-free/http://www.cplusplus.com/reference/stack/stack/uses_allocator/
  • 7/24/2019 Escenciales Stl

    11/19

    std::settemplate < class T, set**key_type0alue_type class :ompare less, set**key_compare0alue_compare class /lloc allocator set**allocator_type > class set;

    #et

    Sets are containers that store uni&ue elements following a specific order.

    n a set, the value of an element also identifies it (the value is itself the key, of type T), and each value must be uni&ue. The value of the

    elements in a setcannot be modified once in the container (the elements are always const), but they can be inserted or removed from the

    container.

    nternally, the elements in a setare always sorted following a specificstrict weak orderingcriterion indicated by its internalcomparison

    ob%ect(of type :ompare).

    setcontainers are generally slower thanunordered2setcontainers to access individual elements by their key, but they allow the direct

    iteration on subsets based on their order.

    Sets are typically implemented as binary search trees.

    ,ontainer properties

    Associative

    !lements in associative containers are referenced by their keyand not by their absolute position in the container.

    Ordered The elements in the container follow a strict order at all times. All inserted elements are given a position in this order.

    Set

    The value of an element is also the keyused to identify it.

    Unique keys

    +o two elements in the container can have e&uivalent keys.

    Allocator-aware

    The container uses an allocator ob%ect to dynamically handle its storage needs.

    Template parameters

    T

    Type of the elements. !ach element in a setcontainer is also uni&uely identified by this value (each value is itself also the

    element7s 4ey).

    Aliased as member types set**key_typeand set**0alue_type.

    :ompare

    A binary predicate that ta4es two arguments of the same type as the elements and returns a +ool. The e"pressioncomp(a,+),

    where compis an ob%ect of this type and aand bare 4ey values, shall return trueif ais considered to go before bin thestrict

    weak orderingthe function defines.

    The setob%ect uses this e"pression to determine both the order the elements follow in the container and whether two element 4eys

    are e&uivalent (by comparing them refle"ively' they are e&uivalent if @comp(a,+) 66 @comp(+,a)). +o two elements in

    a setcontainer can be e&uivalent.

    This can be a function pointer or a function ob%ect (see constructorfor an e"ample). This defaults toless, which returns the

    same as applying the less-than operator(a

  • 7/24/2019 Escenciales Stl

    12/19

    member type definition notes

    key_type The first template parameter (T)

    0alue_type The first template parameter (T)

    key_compare The second template parameter (:ompare) defaults to: less

    0alue_compare The second template parameter (:ompare) defaults to: less

    allocator_type The third template parameter (/lloc)defaultsto:allocator

    reference allocator_type**referencefor the

    default allocator:0alue_type6

    const_reference allocator_type**const_referencefor the

    default allocator: const0alue_type6

    pointer allocator_type**pointerfor thedefault allocator:0alue_type=

    const_pointer allocator_type**const_pointerfor thedefault allocator: const0alue_type=

    iterator a bidirectional iteratorto 0alue_typeconvertibleto const_iterator

    const_iterator a bidirectional iteratorto const 0alue_type

    re0erse_iterator reverse2iterator

    const_re0erse_iterator reverse2iterator

    difference_typea si$ned inte$ral type identicalto:iterator_traits**difference_type

    usually the same as ptrdiff_t

    sie_typean unsi$ned inte$ral type that can represent any nonne$ative value of difference_type

    usually the same as si*e_t

    Member functions

    (constructor)

    Construct set (public member function )

    (destructor)

    Set destructor (public member function )

    operator=

    Copy container content (public member function )

    terators'

    begin

    eturn iterator to beginning (public member function )

    end

    eturn iterator to end (public member function )

    rbegin

    eturn reverse iterator to reverse beginning (public member function )

    rend

    eturn reverse iterator to reverse end (public member function )

    cbegin

    eturn const2iterator to beginning (public member function )

    cend

    eturn const2iterator to end (public member function )

    crbegin

    eturn const2reverse2iterator to reverse beginning (public member function )

    crend

    eturn const2reverse2iterator to reverse end (public member function )

    ,apacity'

    empty

    http://www.cplusplus.com/lesshttp://www.cplusplus.com/lesshttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/reverse_iteratorhttp://www.cplusplus.com/reverse_iteratorhttp://www.cplusplus.com/ptrdiff_thttp://www.cplusplus.com/size_thttp://www.cplusplus.com/reference/set/set/set/http://www.cplusplus.com/reference/set/set/~set/http://www.cplusplus.com/reference/set/set/operator=/http://www.cplusplus.com/reference/set/set/begin/http://www.cplusplus.com/reference/set/set/end/http://www.cplusplus.com/reference/set/set/rbegin/http://www.cplusplus.com/reference/set/set/rend/http://www.cplusplus.com/reference/set/set/cbegin/http://www.cplusplus.com/reference/set/set/cend/http://www.cplusplus.com/reference/set/set/crbegin/http://www.cplusplus.com/reference/set/set/crend/http://www.cplusplus.com/reference/set/set/empty/http://www.cplusplus.com/lesshttp://www.cplusplus.com/lesshttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/reverse_iteratorhttp://www.cplusplus.com/reverse_iteratorhttp://www.cplusplus.com/ptrdiff_thttp://www.cplusplus.com/size_thttp://www.cplusplus.com/reference/set/set/set/http://www.cplusplus.com/reference/set/set/~set/http://www.cplusplus.com/reference/set/set/operator=/http://www.cplusplus.com/reference/set/set/begin/http://www.cplusplus.com/reference/set/set/end/http://www.cplusplus.com/reference/set/set/rbegin/http://www.cplusplus.com/reference/set/set/rend/http://www.cplusplus.com/reference/set/set/cbegin/http://www.cplusplus.com/reference/set/set/cend/http://www.cplusplus.com/reference/set/set/crbegin/http://www.cplusplus.com/reference/set/set/crend/http://www.cplusplus.com/reference/set/set/empty/
  • 7/24/2019 Escenciales Stl

    13/19

    Test whether container is empty (public member function )

    size

    eturn container si$e (public member function )

    ma_size

    eturn ma"imum si$e (public member function )

    Modifiers'

    insert

    nsert element (public member function )erase

    !rase elements (public member function )

    swap

    Swap content (public member function )

    clear

    Clear content (public member function )

    emplace

    Construct and insert element (public member function )

    emplace_+int

    Construct and insert element with hint (public member function )

    .bservers'

    #ey_comp

    eturn comparison ob%ect (public member function )

    value_comp

    eturn comparison ob%ect (public member function )

    .perations'

    find

    #et iterator to element (public member function )

    count

    Count elements with a specific value (public member function )

    lower_boundeturn iterator to lower bound (public member function )

    upper_bound

    eturn iterator to upper bound (public member function )

    e*ual_range

    #et range of e&ual elements (public member function )

    /llocator'

    get_allocator

    #et allocator (public member function )

    http://www.cplusplus.com/reference/set/set/size/http://www.cplusplus.com/reference/set/set/max_size/http://www.cplusplus.com/reference/set/set/insert/http://www.cplusplus.com/reference/set/set/erase/http://www.cplusplus.com/reference/set/set/swap/http://www.cplusplus.com/reference/set/set/clear/http://www.cplusplus.com/reference/set/set/emplace/http://www.cplusplus.com/reference/set/set/emplace_hint/http://www.cplusplus.com/reference/set/set/key_comp/http://www.cplusplus.com/reference/set/set/value_comp/http://www.cplusplus.com/reference/set/set/find/http://www.cplusplus.com/reference/set/set/count/http://www.cplusplus.com/reference/set/set/lower_bound/http://www.cplusplus.com/reference/set/set/upper_bound/http://www.cplusplus.com/reference/set/set/equal_range/http://www.cplusplus.com/reference/set/set/get_allocator/http://www.cplusplus.com/reference/set/set/size/http://www.cplusplus.com/reference/set/set/max_size/http://www.cplusplus.com/reference/set/set/insert/http://www.cplusplus.com/reference/set/set/erase/http://www.cplusplus.com/reference/set/set/swap/http://www.cplusplus.com/reference/set/set/clear/http://www.cplusplus.com/reference/set/set/emplace/http://www.cplusplus.com/reference/set/set/emplace_hint/http://www.cplusplus.com/reference/set/set/key_comp/http://www.cplusplus.com/reference/set/set/value_comp/http://www.cplusplus.com/reference/set/set/find/http://www.cplusplus.com/reference/set/set/count/http://www.cplusplus.com/reference/set/set/lower_bound/http://www.cplusplus.com/reference/set/set/upper_bound/http://www.cplusplus.com/reference/set/set/equal_range/http://www.cplusplus.com/reference/set/set/get_allocator/
  • 7/24/2019 Escenciales Stl

    14/19

    class template

    std::maptemplate < class Bey, map**key_type class T, map**mapped_type class :ompare less, map**key_compare class /lloc allocator map**allocator_type > class map;

    $ap

    8aps are associative containers that store elements formed by a combination of a key valueand a mapped value, following a specific order.

    n a map, the key valuesare generally used to sort and uni&uely identify the elements, while the mapped valuesstore the content associated

    to this key. The types of keyand mapped valuemay differ, and are grouped together in member type0alue_type, which is apairtype

    combining both'

    typedefpair 0alue_type;

    nternally, the elements in a mapare always sorted by its keyfollowing a specificstrict weak orderingcriterion indicated by its

    internalcomparison ob%ect(of type :ompare).

    mapcontainers are generally slower thanunordered2mapcontainers to access individual elements by their key, but they allow the direct

    iteration on subsets based on their order.

    The mapped values in amapcan be accessed directly by their corresponding 4ey using the bracket operator((operator9:).

    8aps are typically implemented as binary search trees.

    ,ontainer properties

    Associative

    !lements in associative containers are referenced by their keyand not by their absolute position in the container.

    Ordered

    The elements in the container follow a strict order at all times. All inserted elements are given a position in this order.

    Map

    !ach element associates a keyto a mapped value' ;eys are meant to identify the elements whose main content is the mapped value.Unique keys

    +o two elements in the container can have e&uivalent keys.

    Allocator-aware

    The container uses an allocator ob%ect to dynamically handle its storage needs.

    Template parameters

    Bey

    Type of the keys. !ach element in a mapis uni&uely identified by its 4ey value.

    Aliased as member type map**key_type.

    T

    Type of the mapped value. !ach element in a mapstores some data as its mapped value.

    Aliased as member type map**mapped_type.:ompare

    A binary predicate that ta4es two element 4eys as arguments and returns a +ool. The e"pression comp(a,+), where compis an

    ob%ect of this type and aand bare 4ey values, shall return trueif ais considered to go before bin thestrict weak orderingthe

    function defines.

    The mapob%ect uses this e"pression to determine both the order the elements follow in the container and whether two element 4eys

    are e&uivalent (by comparing them refle"ively' they are e&uivalent if @comp(a,+) 66 @comp(+,a)). +o two elements in

    a mapcontainer can have e&uivalent 4eys.

    This can be a function pointer or a function ob%ect (see constructorfor an e"ample). This defaults toless, which returns the

    same as applying the less-than operator(a

  • 7/24/2019 Escenciales Stl

    15/19

    Type of the allocator ob%ect used to define the storage allocation model. -y default, theallocatorclass template is used, which

    defines the simplest memory allocation model and is valueindependent.Aliased as member type map**allocator_type.

    Member types

    C/0

    C11

    member type definition notes

    key_type The first template parameter (Bey)

    mapped_type The second template parameter (T)

    0alue_type pair

    key_compare The third template parameter (:ompare) defaults to: less

    0alue_compare Nested function class to compare elements see value_comp

    allocator_type The fourth template parameter (/lloc)defaultsto:allocator

    reference allocator_type**reference

    for thedefault allocator:0alue_type6

    const_reference allocator_type**const_referencefor thedefault allocator: const0alue_type6

    pointer allocator_type**pointerfor thedefault allocator:0alue_type=

    const_pointer allocator_type**const_pointerfor thedefault allocator: const0alue_type=

    iterator a bidirectional iteratorto 0alue_typeconvertibleto const_iterator

    const_iterator a bidirectional iteratorto const 0alue_typere0erse_iterator reverse2iterator

    const_re0erse_iterator reverse2iterator

    difference_typea si$ned inte$ral type identicalto:iterator_traits**difference_type

    usually the same as ptrdiff_t

    sie_typean unsi$ned inte$ral type that can represent any nonne$ative value of difference_type

    usually the same as si*e_t

    Member functions

    (constructor)

    Construct map (public member function )

    (destructor)

    8ap destructor (public member function )

    operator=

    Copy container content (public member function )

    terators'

    begin

    eturn iterator to beginning (public member function )

    end

    eturn iterator to end (public member function )

    rbegin

    http://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://switch1.select%281%29/http://switch1.select%282%29/http://www.cplusplus.com/pairhttp://www.cplusplus.com/lesshttp://www.cplusplus.com/map::value_comphttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/reverse_iteratorhttp://www.cplusplus.com/reverse_iteratorhttp://www.cplusplus.com/ptrdiff_thttp://www.cplusplus.com/size_thttp://www.cplusplus.com/reference/map/map/map/http://www.cplusplus.com/reference/map/map/~map/http://www.cplusplus.com/reference/map/map/operator=/http://www.cplusplus.com/reference/map/map/begin/http://www.cplusplus.com/reference/map/map/end/http://www.cplusplus.com/reference/map/map/rbegin/http://www.cplusplus.com/allocatorhttp://switch1.select%281%29/http://switch1.select%282%29/http://www.cplusplus.com/pairhttp://www.cplusplus.com/lesshttp://www.cplusplus.com/map::value_comphttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/allocatorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/BidirectionalIteratorhttp://www.cplusplus.com/reverse_iteratorhttp://www.cplusplus.com/reverse_iteratorhttp://www.cplusplus.com/ptrdiff_thttp://www.cplusplus.com/size_thttp://www.cplusplus.com/reference/map/map/map/http://www.cplusplus.com/reference/map/map/~map/http://www.cplusplus.com/reference/map/map/operator=/http://www.cplusplus.com/reference/map/map/begin/http://www.cplusplus.com/reference/map/map/end/http://www.cplusplus.com/reference/map/map/rbegin/
  • 7/24/2019 Escenciales Stl

    16/19

    eturn reverse iterator to reverse beginning (public member function )

    rend

    eturn reverse iterator to reverse end (public member function )

    cbegin

    eturn const2iterator to beginning (public member function )

    cend

    eturn const2iterator to end (public member function )

    crbegin

    eturn const2reverse2iterator to reverse beginning (public member function )

    crendeturn const2reverse2iterator to reverse end (public member function )

    ,apacity'

    empty

    Test whether container is empty (public member function )

    size

    eturn container si$e (public member function )

    ma_size

    eturn ma"imum si$e (public member function )

    'lement access'

    operator01

    Access element (public member function )

    at

    Access element (public member function )

    Modifiers'

    insert

    nsert elements (public member function )

    erase

    !rase elements (public member function )

    swap Swap content (public member function )

    clear

    Clear content (public member function )

    emplace

    Construct and insert element (public member function )

    emplace_+int

    Construct and insert element with hint (public member function )

    .bservers'

    #ey_comp

    eturn 4ey comparison ob%ect (public member function )

    value_competurn value comparison ob%ect (public member function )

    .perations'

    find

    #et iterator to element (public member function )

    count

    Count elements with a specific 4ey (public member function )

    lower_bound

    eturn iterator to lower bound (public member function )

    http://www.cplusplus.com/reference/map/map/rend/http://www.cplusplus.com/reference/map/map/cbegin/http://www.cplusplus.com/reference/map/map/cend/http://www.cplusplus.com/reference/map/map/crbegin/http://www.cplusplus.com/reference/map/map/crend/http://www.cplusplus.com/reference/map/map/empty/http://www.cplusplus.com/reference/map/map/size/http://www.cplusplus.com/reference/map/map/max_size/http://www.cplusplus.com/reference/map/map/operator%5B%5D/http://www.cplusplus.com/reference/map/map/at/http://www.cplusplus.com/reference/map/map/insert/http://www.cplusplus.com/reference/map/map/erase/http://www.cplusplus.com/reference/map/map/swap/http://www.cplusplus.com/reference/map/map/clear/http://www.cplusplus.com/reference/map/map/emplace/http://www.cplusplus.com/reference/map/map/emplace_hint/http://www.cplusplus.com/reference/map/map/key_comp/http://www.cplusplus.com/reference/map/map/value_comp/http://www.cplusplus.com/reference/map/map/find/http://www.cplusplus.com/reference/map/map/count/http://www.cplusplus.com/reference/map/map/lower_bound/http://www.cplusplus.com/reference/map/map/rend/http://www.cplusplus.com/reference/map/map/cbegin/http://www.cplusplus.com/reference/map/map/cend/http://www.cplusplus.com/reference/map/map/crbegin/http://www.cplusplus.com/reference/map/map/crend/http://www.cplusplus.com/reference/map/map/empty/http://www.cplusplus.com/reference/map/map/size/http://www.cplusplus.com/reference/map/map/max_size/http://www.cplusplus.com/reference/map/map/operator%5B%5D/http://www.cplusplus.com/reference/map/map/at/http://www.cplusplus.com/reference/map/map/insert/http://www.cplusplus.com/reference/map/map/erase/http://www.cplusplus.com/reference/map/map/swap/http://www.cplusplus.com/reference/map/map/clear/http://www.cplusplus.com/reference/map/map/emplace/http://www.cplusplus.com/reference/map/map/emplace_hint/http://www.cplusplus.com/reference/map/map/key_comp/http://www.cplusplus.com/reference/map/map/value_comp/http://www.cplusplus.com/reference/map/map/find/http://www.cplusplus.com/reference/map/map/count/http://www.cplusplus.com/reference/map/map/lower_bound/
  • 7/24/2019 Escenciales Stl

    17/19

    upper_bound

    eturn iterator to upper bound (public member function )

    e*ual_range

    #et range of e&ual elements (public member function )

    /llocator'

    get_allocator

    #et allocator (public member function )

    public member function

    std::map::map

    C++98

    C++

    C++'

    empty (1)

    explicit map (const key_compare6 comp key_compare(), const allocator_type6 alloc allocator_type());

    range (2)

    template map (5nput5terator first, 5nput5terator last, const key_compare6 comp key_compare(), const allocator_type6 alloc allocator_type());

    copy (3)map (const map6 x);

    Construct map

    Constructs a mapcontainer ob%ect, initiali$ing its contents depending on the constructor version used'

    C/0

    C11

    (1) empty container constructor (deault constructor)

    Constructs anemptycontainer, with no elements.

    (2) ran!e constructor

    Constructs a container with as many elements as the range first,last), with each element constructed from its

    corresponding element in that range.

    (") copy constructor

    Constructs a container with a copy of each of the elements inx.

    The container 4eeps an internal copy of allocand comp, which are used to allocate storage and to sort the elements throughout its lifetime.

    The copy constructor (3)creates a container that 4eeps and uses copies ofx7sallocatorandcomparison ob%ect.

    The storage for the elements is allocated using thisinternal allocator.

    The elements are sorted according to the comparison ob%ect. f more than one element with e&uivalent 4eys is passed to the constructor, only

    the first one is preserved.

    $arameters

    comp

    -inary predicate that, ta4ing two element keysas argument, returns trueif the first argument goes before the second argument in

    thestrict weak orderingit defines, and falseotherwise.

    This shall be a function pointer or a function ob%ect.8ember type key_compareis the internal comparison ob%ect type used by the container, defined in mapas an alias of its third

    http://www.cplusplus.com/reference/map/map/upper_bound/http://www.cplusplus.com/reference/map/map/equal_range/http://www.cplusplus.com/reference/map/map/get_allocator/http://www.cplusplus.com/reference/map/map/http://switch1.select%281%29/http://switch1.select%282%29/http://switch1.select%283%29/http://www.cplusplus.com/maphttp://www.cplusplus.com/maphttp://switch2.select%281%29/http://switch2.select%282%29/http://www.cplusplus.com/map::emptyhttp://www.cplusplus.com/map::emptyhttp://www.cplusplus.com/map::emptyhttp://www.cplusplus.com/map::get_allocatorhttp://www.cplusplus.com/map::get_allocatorhttp://www.cplusplus.com/map::get_allocatorhttp://www.cplusplus.com/map::key_comphttp://www.cplusplus.com/map::key_comphttp://www.cplusplus.com/map::key_comphttp://www.cplusplus.com/map::get_allocatorhttp://www.cplusplus.com/map::get_allocatorhttp://www.cplusplus.com/map::get_allocatorhttp://www.cplusplus.com/map::key_comphttp://www.cplusplus.com/maphttp://www.cplusplus.com/maphttp://www.cplusplus.com/reference/map/map/upper_bound/http://www.cplusplus.com/reference/map/map/equal_range/http://www.cplusplus.com/reference/map/map/get_allocator/http://www.cplusplus.com/reference/map/map/http://switch1.select%281%29/http://switch1.select%282%29/http://switch1.select%283%29/http://www.cplusplus.com/maphttp://switch2.select%281%29/http://switch2.select%282%29/http://www.cplusplus.com/map::emptyhttp://www.cplusplus.com/map::get_allocatorhttp://www.cplusplus.com/map::key_comphttp://www.cplusplus.com/map::get_allocatorhttp://www.cplusplus.com/map::key_comphttp://www.cplusplus.com/map
  • 7/24/2019 Escenciales Stl

    18/19

    template parameter (:ompare).

    f key_compareuses the default less(which has no state), this parameter is not relevant.

    alloc

    Allocator ob%ect.The container 4eeps and uses an internal copy of this allocator.

    8ember type allocator_typeis the internal allocator type used by the container, defined inmapas an alias of its fourth

    template parameter (/lloc).

    f allocator_typeis an instantiation of the default allocator(which has no state), this parameter is not relevant.

    first, last

    nput iteratorsto the initial and final positions in a range. The range used is first,last), which includes all the elementsbetweenfirstand last, including the element pointed byfirstbut not the element pointed by last.

    The function template argument 5nput5teratorshall be an input iteratortype that points to elements of a type from

    which 0alue_typeob%ects can be constructed (inmap, 0alue_typeis an alias ofpair)

    x

    Anothermapob%ect of the same type (with the same class template arguments Bey, T, :ompareand /lloc), whose contents are

    either copied or ac&uired.

    il

    An initiali$er2listob%ect.

    These ob%ects are automatically constructed from initialier listdeclarators.8ember type 0alue_typeis the type of the elements in the container, defined inmapas an alias ofpair(seemap types).

    'ample

    1234#$%&1'1112

    131411#1$1%1&2'2122232422#2$

    2%2&3'31

    constructin7 mapsinclude include

    +oolfncomp (carls, carrs) !returnls

  • 7/24/2019 Escenciales Stl

    19/19

    Constant for the empty constructors (1), and for the move constructors (!)(unless allocis different fromx7s allocator).

    or all other cases, linear in the distance between the iterators (copy constructions) if the elements are already sorted according to the samecriterion. or unsorted se&uences, linearithmic (=lo7) in that distance (sorting,copy constructions).

    terator validity

    The move constructors(