<map>


Include the STL standard header <map> to define the container template classes map and multimap, and their supporting templates.

namespace std {
template<class Key, class Ty, class Pr, class Alloc>
    class map;
template<class Key, class Ty, class Pr, class Alloc>
    class multimap;

        // TEMPLATE FUNCTIONS
template<class Key, class Ty, class Pr, class Alloc>
    bool operator==(
        const map<Key, Ty, Pr, Alloc>& left,
        const map<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator==(
        const multimap<Key, Ty, Pr, Alloc>& left,
        const multimap<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator!=(
        const map<Key, Ty, Pr, Alloc>& left,
        const map<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator!=(
        const multimap<Key, Ty, Pr, Alloc>& left,
        const multimap<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator<(
        const map<Key, Ty, Pr, Alloc>& left,
        const map<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator<(
        const multimap<Key, Ty, Pr, Alloc>& left,
        const multimap<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator>(
        const map<Key, Ty, Pr, Alloc>& left,
        const map<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator>(
        const multimap<Key, Ty, Pr, Alloc>& left,
        const multimap<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator<=(
        const map<Key, Ty, Pr, Alloc>& left,
        const map<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator<=(
        const multimap<Key, Ty, Pr, Alloc>& left,
        const multimap<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator>=(
        const map<Key, Ty, Pr, Alloc>& left,
        const map<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator>=(
        const multimap<Key, Ty, Pr, Alloc>& left,
        const multimap<Key, Ty, Pr, Alloc>& right);

template<class Key, class Ty, class Pr, class Alloc>
    void swap(
        map<Key, Ty, Pr, Alloc>& left,
        map<Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    void swap(
        multimap<Key, Ty, Pr, Alloc>& left,
        multimap<Key, Ty, Pr, Alloc>& right);
}  // namespace std

map


allocator_type · at · begin · cbegin · cend · clear · const_iterator · const_pointer · const_reference · const_reverse_iterator · count · crbegin · crend · difference_type · emplace · emplace_hint · empty · end · equal_range · erase · find · get_allocator · insert · iterator · key_comp · key_compare · key_type · lower_bound · map · mapped_type · max_size · operator= · operator[] · pointer · rbegin · reference · rend · reverse_iterator · size · size_type · swap · upper_bound · value_comp · value_compare · value_type


template<class Key, class Ty, class Pr = less<Key>,
    class Alloc = allocator<pair<const Key, Ty> > >
    class map {
public:
    typedef Key key_type;
    typedef Ty mapped_type;
    typedef Pr key_compare;
    typedef Alloc allocator_type;
    typedef pair<const Key, Ty> value_type;
    class value_compare;
    typedef typename Alloc::pointer pointer;
    typedef typename Alloc::const_pointer const_pointer;
    typedef typename Alloc::reference reference;
    typedef typename Alloc::const_reference const_reference;
    typedef typename Alloc::size_type size_type;
    typedef typename Alloc::difference_type difference_type;

    typedef T0 iterator;
    typedef T1 const_iterator;
    typedef reverse_iterator<const_iterator>
        const_reverse_iterator;
    typedef reverse_iterator<iterator> reverse_iterator;

    map();
    explicit map(const Alloc& al); [added with C++11]
    explicit map(const Pr& pred);
    map(const Pr& pred, const Alloc& al);

    map(const map& right);
    map(const map& right, const Alloc& al); [added with C++11]
    map(map&& right); [added with C++11]
    map(map&& right, const Alloc& al); [added with C++11]

    template<class InIt>
        map(InIt first, InIt last);
    template<class InIt>
        map(InIt first, InIt last,
            const Pr& pred);
    template<class InIt>
        map(InIt first, InIt last,
        const Pr& pred, const Alloc& al);

    map(initializer_list<Ty> init) [added with C++11]
    map(initializer_list<Ty> init,
        const Pr& pred); [added with C++11]
    map(initializer_list<Ty> init,
        const Pr& pred, const Alloc& al); [added with C++11]

    map& operator=(const map& right);
    map& operator=(initializer_list<Ty> init) [added with C++11]
    map& operator=(map&& right); [added with C++11]

    iterator begin() noexcept;
    const_iterator begin() const noexcept;
    iterator end() noexcept;
    const_iterator end() const noexcept;
    reverse_iterator rbegin() noexcept;
    const_reverse_iterator rbegin() const noexcept;
    reverse_iterator rend() noexcept;
    const_reverse_iterator rend() const noexcept;

    const_iterator cbegin() const noexcept; [added with C++11]
    const_iterator cend() const noexcept; [added with C++11]
    const_reverse_iterator crbegin() const noexcept; [added with C++11]
    const_reverse_iterator crend() const noexcept; [added with C++11]

    size_type size() const noexcept;
    size_type max_size() const noexcept;
    bool empty() const noexcept;
    Alloc get_allocator() const noexcept;

    mapped_type& operator[](const Key& keyval);
    mapped_type& operator[](Key&& keyval); [added with C++11]

    mapped_type& at(const Key& keyval); [added with C++11]
    const mapped_type& at(const Key& keyval); const [added with C++11]

    pair<iterator, bool> insert(const value_type& val);
    iterator insert(const_iterator where, const value_type& val);
    template<class InIt>
        void insert(InIt first, InIt last);
    void insert(initializer_list<Ty> init) [added with C++11]
    template<class Valty>
        pair<iterator, bool> insert(Valty&& val); [added with C++11]
    template<class Valty>
        iterator insert(const_iterator where, Valty&& val); [added with C++11]

    template<class... Valty>
        pair<iterator, bool> emplace(Valty&&... val); [added with C++11]
    template<class... Valty>
        iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11]

    iterator erase(const_iterator where);
    iterator erase(const_iterator first, const_iterator last);
    size_type erase(const Key& keyval);
    void clear() noexcept;

    void swap(map& right);

    key_compare key_comp() const;
    value_compare value_comp() const;

    iterator find(const Key& keyval);
    const_iterator find(const Key& keyval) const;
    size_type count(const Key& keyval) const;
    iterator lower_bound(const Key& keyval);
    const_iterator lower_bound(const Key& keyval) const;
    iterator upper_bound(const Key& keyval);
    const_iterator upper_bound(const Key& keyval) const;
    pair<iterator, iterator> equal_range(const Key& keyval);
    pair<const_iterator, const_iterator>
        equal_range(const Key& keyval) const;
    };

The template class describes an object that controls a varying-length sequence of elements of type pair<const Key, Ty>. The sequence is ordered by the predicate Pr. The first element of each pair is the sort key and the second is its associated value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element with a number of operations proportional to the logarithm of the number of elements in the sequence (logarithmic time). Moreover, inserting an element invalidates no iterators, and removing an element invalidates only those iterators which point at the removed element.

The object orders the sequence it controls by calling a stored function object of type Pr. You access this stored object by calling the member function key_comp(). Such a function object must impose a strict weak ordering on sort keys of type Key. For any element X that precedes Y in the sequence, key_comp()(Y.first, X.first) is false. (For the default function object less<Key>, sort keys never decrease in value.) Unlike template class multimap, an object of template class map ensures that key_comp()(X.first, Y.first) is true. (Each key is unique.)

The object allocates and frees storage for the sequence it controls through a stored allocator object of class Alloc. Such an allocator object must have the same external interface as an object of template class allocator.

map::allocator_type

typedef Alloc allocator_type;

The type is a synonym for the template parameter Alloc.

map::at

const mapped_type& at(const Key& keyval) const; [added with C++11]
mapped_type& at(const Key& keyval); [added with C++11]

The member function effectively determines the iterator where as the return value of find(keyval). If that iterator does not designate an element whose sort key has equivalent ordering to keyval, the function throws an object of class out_of_range. Otherwise, it returns a reference to (*where).second.

map::begin

const_iterator begin() const noexcept;
iterator begin() noexcept;

The member function returns a bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).

map::cbegin

const_iterator cbegin() const noexcept; [added with C++11]

The member functions return a bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).

map::cend

const_reference cend() const noexcept; [added with C++11]

The member functions return a bidirectional iterator that points just beyond the end of the sequence.

map::clear

void clear() noexcept;

The member function calls erase( begin(), end()).

map::const_iterator

typedef T1 const_iterator;

The type describes an object that can serve as a constant bidirectional iterator for the controlled sequence. It is described here as a synonym for the implementation-defined type T1.

map::const_pointer

typedef typename Alloc::const_pointer const_pointer;

The type describes an object that can serve as a constant pointer to an element of the controlled sequence.

map::const_reference

typedef typename Alloc::const_reference const_reference;

The type describes an object that can serve as a constant reference to an element of the controlled sequence.

map::const_reverse_iterator

typedef reverse_iterator<const_iterator>
    const_reverse_iterator;

The type describes an object that can serve as a constant reverse bidirectional iterator for the controlled sequence.

map::count

size_type count(const Key& keyval) const;

The member function returns the number of elements in the range [lower_bound(keyval), upper_bound(keyval)).

map::crbegin

const_reverse_iterator crbegin() const noexcept; [added with C++11]

The member functions return a reverse iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.

map::crend

const_reverse_iterator crend() const noexcept; [added with C++11]

The member functions return a reverse iterator that points at the first element of the sequence (or just beyond the end of an empty sequence)). Hence, it designates the end of the reverse sequence.

map::difference_type

typedef typename Alloc::difference_type difference_type;

The signed integer type describes an object that can represent the difference between the addresses of any two elements in the controlled sequence.

map::emplace

template<class... Valty>
    pair<iterator, bool> emplace(Valty&&... val); [added with C++11]

The member function effectively returns insert(value_type(forward<Valty>(val)...)), except that the element value is constructed in place.

map::emplace_hint

template<class... Valty>
    iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11]

The member function effectively returns insert(where, value_type(forward<Valty>(val)...)), except that the element value is constructed in place.

map::empty

bool empty() const noexcept;

The member function returns true for an empty controlled sequence.

map::end

const_iterator end() const noexcept;
iterator end() noexcept;

The member function returns a bidirectional iterator that points just beyond the end of the sequence.

map::equal_range

pair<iterator, iterator> equal_range(const Key& keyval);
pair<const_iterator, const_iterator>
    equal_range(const Key& keyval) const;

The member function returns a pair of iterators X such that X.first == lower_bound(keyval) and X.second == upper_bound(keyval).

map::erase

iterator erase(const_iterator where);
iterator erase(const_iterator first, const_iterator last);
size_type erase(const Key& keyval);

The first member function removes the element of the controlled sequence pointed to by where. The second member function removes the elements in the interval [first, last). Both return an iterator that designates the first element remaining beyond any elements removed, or end() if no such element exists.

The third member function removes the elements with sort keys in the range [lower_bound(keyval), upper_bound(keyval)). It returns the number of elements it removes.

The member functions never throw an exception.

In this implementation, the first two member functions return an iterator that designates the first element remaining beyond any elements removed, or end() if no such element exists.

map::find

iterator find(const Key& keyval);
const_iterator find(const Key& keyval) const;

The member function returns an iterator that designates the element in the controlled sequence whose sort key has equivalent ordering to keyval. If no such element exists, the function returns end().

map::get_allocator

Alloc get_allocator() const noexcept;

The member function returns the stored allocator object.

map::insert

pair<iterator, bool> insert(const value_type& val);
iterator insert(const_iterator where, const value_type& val);
template<class InIt>
    void insert(InIt first, InIt last);
void insert(initializer_list<Ty> init) [added with C++11]
template<class Valty>
    pair<iterator, bool> insert(Valty&& val); [added with C++11]
template<class Valty>
    iterator insert(const_iterator where, Valty&& val); [added with C++11]

The first member function determines whether an element X exists in the sequence whose key has equivalent ordering to that of val. If not, it creates such an element X and initializes it with val. The function then determines the iterator where that designates X. If an insertion occurred, the function returns pair(where, true). Otherwise, it returns pair(where, false).

The second member function returns insert(val).first, using where as a starting place within the controlled sequence to search for the insertion point. (Insertion can occur in amortized constant time, instead of logarithmic time, if the insertion point immediately precedes or follows where.)

The third member function inserts the sequence of element values, for each where in the range [first, last), by calling insert(*where).

The fourth member function inserts the sequence specified by an object of class initializer_list<Ty>.

The last two member functions behave the same as the first two but with an rvalue reference.

If an exception is thrown during the insertion of a single element, the container is left unaltered and the exception is rethrown. If an exception is thrown during the insertion of multiple elements, the container is left in a stable but unspecified state and the exception is rethrown.

map::iterator

typedef T0 iterator;

The type describes an object that can serve as a bidirectional iterator for the controlled sequence. It is described here as a synonym for the implementation-defined type T0.

map::key_comp

key_compare key_comp() const;

The member function returns the stored function object that determines the order of elements in the controlled sequence. The stored object defines the member function:

bool operator()(const Key& left, const Key& right);

which returns true if left strictly precedes right in the sort order.

map::key_compare

typedef Pr key_compare;

The type describes a function object that can compare two sort keys to determine the relative order of two elements in the controlled sequence.

map::key_type

typedef Key key_type;

The type describes the sort key object stored in each element of the controlled sequence.

map::lower_bound

iterator lower_bound(const Key& keyval);
const_iterator lower_bound(const Key& keyval) const;

The member function returns an iterator that designates the earliest element X in the controlled sequence for which key_comp()(X. first, keyval) is false.

If no such element exists, the function returns end().

map::map

map();
explicit map(const Alloc& al); [added with C++11]
explicit map(const Pr& pred);
map(const Pr& pred, const Alloc& al);

map(const map& right);
map(const map& right, const Alloc& al); [added with C++11]
map(map&& right); [added with C++11]
map(map&& right, const Alloc& al); [added with C++11]

template<class InIt>
    map(InIt first, InIt last);
template<class InIt>
    map(InIt first, InIt last,
        const Pr& pred);
template<class InIt>
    map(InIt first, InIt last,
        const Pr& pred, const Alloc& al);

map(initializer_list<Ty> init) [added with C++11]
map(initializer_list<Ty> init,
    const Pr& pred); [added with C++11]
map(initializer_list<Ty> init,
    const Pr& pred, const Alloc& al); [added with C++11]

All constructors store an allocator object and initialize the controlled sequence. The allocator object is the argument al, if present. Otherwise, for the copy and move constructors, it is right.get_allocator(). Otherwise, it is Alloc().

All constructors also store a function object that can later be returned by calling key_comp(). The function object is the argument pred, if present. For the copy constructor, it is right.key_comp()). Otherwise, it is Pr().

The first four constructors specify an empty initial controlled sequence.

The next four constructors specify a copy of the sequence controlled by right. The last two of these constructors are the same as the first two, but with an rvalue reference.

The next three constructors specify the sequence of element values [first, last).

The last three constructors specify the initial controlled sequence with an object of class initializer_list<Ty>.

map::mapped_type

typedef Ty mapped_type;

The type is a synonym for the template parameter Ty.

map::max_size

size_type max_size() const noexcept;

The member function returns the length of the longest sequence that the object can control.

map::operator=

map& operator=(const map& right);
map& operator=(initializer_list<Ty> init) [added with C++11]
map& operator=(map&& right); [added with C++11]

The first member operator replaces the controlled sequence with a copy of the sequence controlled by right.

The second member operator replaces the controlled sequence from an object of class initializer_list<Ty>.

The third member operator is the same as the first, but with an rvalue reference.

map::operator[]

mapped_type& operator[](const Key& keyval);
mapped_type& operator[](Key&& keyval); [added with C++11]

The first member operator effectively determines the iterator where as the return value of insert( value_type(keyval, Ty()). (It inserts an element with the specified key if no such element exists.) It then returns a reference to (*where).second.

The second member operator is the same as the first, but with an rvalue reference.

map::pointer

typedef typename Alloc::pointer pointer;

The type describes an object that can serve as a pointer to an element of the controlled sequence.

map::rbegin

const_reverse_iterator rbegin() const noexcept;
reverse_iterator rbegin() noexcept;

The member function returns a reverse bidirectional iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.

map::reference

typedef typename Alloc::reference reference;

The type describes an object that can serve as a reference to an element of the controlled sequence.

map::rend

const_reverse_iterator rend() const noexcept;
reverse_iterator rend() noexcept;

The member function returns a reverse bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence). Hence, it designates the end of the reverse sequence.

map::reverse_iterator

typedef reverse_iterator<iterator> reverse_iterator;

The type describes an object that can serve as a reverse bidirectional iterator for the controlled sequence.

map::size

size_type size() const noexcept;

The member function returns the length of the controlled sequence.

map::size_type

typedef typename Alloc::size_type size_type;

The unsigned integer type describes an object that can represent the length of any controlled sequence.

map::swap

void swap(map& right);

The member function swaps the controlled sequences between *this and right. If get_allocator() == right.get_allocator(), it does so in constant time, it throws an exception only as a result of copying the stored function object of type Pr, and it invalidates no references, pointers, or iterators that designate elements in the two controlled sequences. Otherwise, it performs a number of element assignments and constructor calls proportional to the number of elements in the two controlled sequences.

map::upper_bound

iterator upper_bound(const Key& keyval);
const_iterator upper_bound(const Key& keyval) const;

The member function returns an iterator that designates the earliest element X in the controlled sequence for which key_comp()(keyval, X.first) is true.

If no such element exists, the function returns end().

map::value_comp

value_compare value_comp() const;

The member function returns a function object that determines the order of elements in the controlled sequence.

map::value_compare

class value_compare
    : public binary_function<value_type, value_type,
        bool> {
public:
    bool operator()(const value_type& left,
        const value_type& right) const
        {return (comp(left.first, right.first)); }
protected:
    value_compare(key_compare pr)
        : comp(pr) {}
    key_compare comp;
    };

The type describes a function object that can compare the sort keys in two elements to determine their relative order in the controlled sequence. The function object stores an object comp of type key_compare. The member function operator() uses this object to compare the sort-key components of two element.

map::value_type

typedef pair<const Key, Ty> value_type;

The type describes an element of the controlled sequence.

multimap


allocator_type · begin · cbegin · cend · clear · const_iterator · const_pointer · const_reference · const_reverse_iterator · count · crbegin · crend · difference_type · emplace · emplace_hint · empty · end · equal_range · erase · find · get_allocator · insert · iterator · key_comp · key_compare · key_type · lower_bound · mapped_type · max_size · multimap · operator= · rbegin · reference · rend · reverse_iterator · size · size_type · swap · upper_bound · value_comp · value_compare · value_type


template<class Key, class Ty, class Pr = less<Key>,
    class Alloc = allocator<pair<const Key, Ty> > >
    class multimap {
public:
    typedef Key key_type;
    typedef Ty mapped_type;
    typedef Pr key_compare;
    typedef Alloc allocator_type;
    typedef pair<const Key, Ty> value_type;
    class value_compare;
    typedef typename Alloc::reference reference;
    typedef typename Alloc::const_reference const_reference;
    typedef typename Alloc::size_type size_type;
    typedef typename Alloc::difference_type difference_type;

    typedef T0 iterator;
    typedef T1 const_iterator;
    typedef reverse_iterator<const_iterator>
        const_reverse_iterator;
    typedef reverse_iterator<iterator> reverse_iterator;

    multimap();
    explicit multimap(const Alloc& al); [added with C++11]
    explicit multimap(const Pr& pred);
    multimap(const Pr& pred, const Alloc& al);

    multimap(const multimap& right);
    multimap(const map& right, const Alloc& al); [added with C++11]
    multimap(map&& right); [added with C++11]
    multimap(map&& right, const Alloc& al); [added with C++11]

    template<class InIt>
        multimap(InIt first, InIt last);
    template<class InIt>
        multimap(InIt first, InIt last,
            const Pr& pred);
    template<class InIt>
        multimap(InIt first, InIt last,
            const Pr& pred, const Alloc& al);

    multimap(initializer_list<Ty> init) [added with C++11]
    multimap(initializer_list<Ty> init,
        const Pr& pred); [added with C++11]
    multimap(initializer_list<Ty> init,
        const Pr& pred, const Alloc& al); [added with C++11]
    multimap(multimap&& right); [added with C++11]

    multimap& operator=(const multimap& right);
    multimap& operator=(initializer_list<Ty> init) [added with C++11]
    multimap& operator=(multimap&& right); [added with C++11]

    iterator begin() noexcept;
    const_iterator begin() const noexcept;
    iterator end() noexcept;
    const_iterator end() const noexcept;
    reverse_iterator rbegin() noexcept;
    const_reverse_iterator rbegin() const noexcept;
    reverse_iterator rend() noexcept;
    const_reverse_iterator rend() const noexcept;

    const_iterator cbegin() const noexcept; [added with C++11]
    const_iterator cend() const noexcept; [added with C++11]
    const_reverse_iterator crbegin() const noexcept; [added with C++11]
    const_reverse_iterator crend() const noexcept; [added with C++11]

    size_type size() const noexcept;
    size_type max_size() const noexcept;
    bool empty() const noexcept;
    Alloc get_allocator() const noexcept;

    iterator insert(const value_type& val);
    iterator insert(const_iterator where, const value_type& val);
    template<class InIt>
        void insert(InIt first, InIt last);
    void insert(initializer_list<Ty> init) [added with C++11]
    template<class Valty>
        iterator insert(Valty&& val); [added with C++11]
    template<class Valty>
        iterator insert(const_iterator where, Valty&& val); [added with C++11]

    template<class... Valty>
        iterator emplace(Valty&&... val); [added with C++11]
    template<class... Valty>
        iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11]

    iterator erase(const_iterator where);
    iterator erase(const_iterator first, const_iterator last);
    size_type erase(const Key& keyval);
    void clear() noexcept;

    void swap(multimap& right);

    key_compare key_comp() const;
    value_compare value_comp() const;

    iterator find(const Key& keyval);
    const_iterator find(const Key& keyval) const;
    size_type count(const Key& keyval) const;
    iterator lower_bound(const Key& keyval);
    const_iterator lower_bound(const Key& keyval) const;
    iterator upper_bound(const Key& keyval);
    const_iterator upper_bound(const Key& keyval) const;
    pair<iterator, iterator> equal_range(const Key& keyval);
    pair<const_iterator, const_iterator>
        equal_range(const Key& keyval) const;
    };

The template class describes an object that controls a varying-length sequence of elements of type pair<const Key, Ty>. The sequence is ordered by the predicate Pr. The first element of each pair is the sort key and the second is its associated value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element with a number of operations proportional to the logarithm of the number of elements in the sequence (logarithmic time). Moreover, inserting an element invalidates no iterators, and removing an element invalidates only those iterators which point at the removed element.

The object orders the sequence it controls by calling a stored function object of type Pr. You access this stored object by calling the member function key_comp(). Such a function object must impose a strict weak ordering on sort keys of type Key. For any element X that precedes Y in the sequence, key_comp()(Y.first, X.first) is false. (For the default function object less<Key>, sort keys never decrease in value.) Unlike template class map, an object of template class multimap does not ensure that key_comp()(X.first, Y.first) is true. (Keys need not be unique.)

The object allocates and frees storage for the sequence it controls through a stored allocator object of class Alloc. Such an allocator object must have the same external interface as an object of template class allocator.

Inserting and erasing elements preserves the order of elements with equivalent ordering.

multimap::allocator_type

typedef Alloc allocator_type;

The type is a synonym for the template parameter Alloc.

multimap::begin

const_iterator begin() const noexcept;
iterator begin() noexcept;

The member function returns a bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).

multimap::cbegin

const_iterator cbegin() const noexcept; [added with C++11]

The member functions return a bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).

multimap::cend

const_reference cend() const noexcept; [added with C++11]

The member functions return a bidirectional iterator that points just beyond the end of the sequence.

multimap::clear

void clear() noexcept;

The member function calls erase( begin(), end()).

multimap::const_iterator

typedef T1 const_iterator;

The type describes an object that can serve as a constant bidirectional iterator for the controlled sequence. It is described here as a synonym for the implementation-defined type T1.

multimap::const_pointer

typedef typename Alloc::const_pointer const_pointer;

The type describes an object that can serve as a constant pointer to an element of the controlled sequence.

multimap::const_reference

typedef typename Alloc::const_reference const_reference;

The type describes an object that can serve as a constant reference to an element of the controlled sequence.

multimap::const_reverse_iterator

typedef reverse_iterator<const_iterator>
    const_reverse_iterator;

The type describes an object that can serve as a constant reverse bidirectional iterator for the controlled sequence.

multimap::count

size_type count(const Key& keyval) const;

The member function returns the number of elements in the range [lower_bound(keyval), upper_bound(keyval)).

multimap::crbegin

const_reverse_iterator crbegin() const noexcept; [added with C++11]

The member functions return a reverse iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.

multimap::crend

const_reverse_iterator crend() const noexcept; [added with C++11]

The member functions return a reverse iterator that points at the first element of the sequence (or just beyond the end of an empty sequence)). Hence, it designates the end of the reverse sequence.

multimap::difference_type

typedef typename Alloc::difference_type difference_type;

The signed integer type describes an object that can represent the difference between the addresses of any two elements in the controlled sequence.

multimap::emplace

template<class... Valty>
    iterator emplace(Valty&&... val); [added with C++11]

The member function effectively returns insert(value_type(forward<Valty>(val)...)), except that the element value is constructed in place.

multimap::emplace_hint

template<class... Valty>
    iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11]

The member function effectively returns insert(where, value_type(forward<Valty>(val)...)), except that the element value is constructed in place.

multimap::empty

bool empty() const noexcept;

The member function returns true for an empty controlled sequence.

multimap::end

const_iterator end() const noexcept;
iterator end() noexcept;

The member function returns a bidirectional iterator that points just beyond the end of the sequence.

multimap::equal_range

pair<iterator, iterator> equal_range(const Key& keyval);
pair<const_iterator, const_iterator>
    equal_range(const Key& keyval) const;

The member function returns a pair of iterators X such that X.first == lower_bound(keyval) and X.second == upper_bound(keyval).

multimap::erase

iterator erase(const_iterator where);
iterator erase(const_iterator first, const_iterator last);
size_type erase(const Key& keyval);

The first member function removes the element of the controlled sequence pointed to by where. The second member function removes the elements in the range [first, last). Both return an iterator that designates the first element remaining beyond any elements removed, or end() if no such element exists.

The third member removes the elements with sort keys in the range [lower_bound(keyval), upper_bound(keyval)). It returns the number of elements it removes.

The member functions never throw an exception, nor do they alter the order of any remaining elements.

In this implementation, the first two member functions return an iterator that designates the first element remaining beyond any elements removed, or end() if no such element exists.

multimap::find

iterator find(const Key& keyval);
const_iterator find(const Key& keyval) const;

The member function returns an iterator that designates the earliest element in the controlled sequence whose sort key has equivalent ordering to keyval. If no such element exists, the function returns end().

multimap::get_allocator

Alloc get_allocator() const noexcept;

The member function returns the stored allocator object.

multimap::insert

iterator insert(const value_type& val);
iterator insert(const_iterator where, const value_type& val);
template<class InIt>
    void insert(InIt first, InIt last);
void insert(initializer_list<Ty> init) [added with C++11]
template<class Valty>
    iterator insert(Valty&& val); [added with C++11]
template<class Valty>
    iterator insert(const_iterator where, Valty&& val); [added with C++11]

The first member function inserts the element val in the controlled sequence, then returns the iterator that designates the inserted element. Beginning with C++11, insertion occurs at the end of a sequence of elements with equivalent ordering.

The second member function returns insert(val), using where as a starting place within the controlled sequence to search for the insertion point. (Insertion can occur in amortized constant time, instead of logarithmic time, if the insertion point immediately precedes or follows where.) Beginning with C++11, insertion occurs at the point nearest the position before where in a sequence of elements with equivalent ordering.

The third member function inserts the sequence of element values, for each where in the range [first, last), by calling insert(*where). Beginning with C++11, insertion of each element occurs at the end of a sequence of elements with equivalent ordering.

The fourth member function inserts the sequence specified by an object of class initializer_list<Ty>.

The last two member functions behave the same as the first two but with an rvalue reference.

If an exception is thrown during the insertion of a single element, the container is left unaltered and the exception is rethrown. If an exception is thrown during the insertion of multiple elements, the container is left in a stable but unspecified state and the exception is rethrown.

The member functions never alter the order of any preexisting elements.

multimap::iterator

typedef T0 iterator;

The type describes an object that can serve as a bidirectional iterator for the controlled sequence. It is described here as a synonym for the implementation-defined type T0.

multimap::key_comp

key_compare key_comp() const;

The member function returns the stored function object that determines the order of elements in the controlled sequence. The stored object defines the member function:

bool operator()(const Key& left, const Key& right);

which returns true if left strictly precedes right in the sort order.

multimap::key_compare

typedef Pr key_compare;

The type describes a function object that can compare two sort keys to determine the relative order of two elements in the controlled sequence.

multimap::key_type

typedef Key key_type;

The type describes the sort key object stored in each element of the controlled sequence.

multimap::lower_bound

iterator lower_bound(const Key& keyval);
const_iterator lower_bound(const Key& keyval) const;

The member function returns an iterator that designates the earliest element X in the controlled sequence for which key_comp()(X. first, keyval) is false.

If no such element exists, the function returns end().

multimap::mapped_type

typedef Ty mapped_type;

The type is a synonym for the template parameter Ty.

multimap::max_size

size_type max_size() const noexcept;

The member function returns the length of the longest sequence that the object can control.

multimap::multimap

multimap();
explicit multimap(const Alloc& al); [added with C++11]
explicit multimap(const Pr& pred);
multimap(const Pr& pred, const Alloc& al);

multimap(const multimap& right);
multimap(const map& right, const Alloc& al); [added with C++11]
multimap(map&& right); [added with C++11]
multimap(map&& right, const Alloc& al); [added with C++11]

template<class InIt>
    multimap(InIt first, InIt last);
template<class InIt>
    multimap(InIt first, InIt last,
        const Pr& pred);
template<class InIt>
    multimap(InIt first, InIt last,
        const Pr& pred, const Alloc& al);

multimap(initializer_list<Ty> init) [added with C++11]
multimap(initializer_list<Ty> init,
    const Pr& pred); [added with C++11]
multimap(initializer_list<Ty> init,
    const Pr& pred, const Alloc& al); [added with C++11]
multimap(multimap&& right); [added with C++11]

All constructors store an allocator object and initialize the controlled sequence. The allocator object is the argument al, if present. Otherwise, for the copy and move constructors, it is right.get_allocator(). Otherwise, it is Alloc().

All constructors also store a function object that can later be returned by calling key_comp(). The function object is the argument pred, if present. For the copy and move constructors, it is right.key_comp()). Otherwise, it is Pr().

The first four constructors specify an empty initial controlled sequence.

The next four constructors specify a copy of the sequence controlled by right. The last two of these constructors are the same as the first two, but with an rvalue reference.

The next three constructors specify the sequence of element values [first, last).

The last three constructors specify the initial controlled sequence with an object of class initializer_list<Ty>.

multimap::operator=

multimap& operator=(const multimap& right);
multimap& operator=(initializer_list<Ty> init) [added with C++11]
multimap& operator=(multimap&& right); [added with C++11]

The first member operator replaces the controlled sequence with a copy of the sequence controlled by right.

The second member operator replaces the controlled sequence from an object of class initializer_list<Ty>.

The third member operator is the same as the first, but with an rvalue reference.

multimap::pointer

typedef typename Alloc::pointer pointer;

The type describes an object that can serve as a pointer to an element of the controlled sequence.

multimap::rbegin

const_reverse_iterator rbegin() const noexcept;
reverse_iterator rbegin() noexcept;

The member function returns a reverse bidirectional iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.

multimap::reference

typedef typename Alloc::reference reference;

The type describes an object that can serve as a reference to an element of the controlled sequence.

multimap::rend

const_reverse_iterator rend() const noexcept;
reverse_iterator rend() noexcept;

The member function returns a reverse bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence). Hence, it designates the end of the reverse sequence.

multimap::reverse_iterator

typedef reverse_iterator<iterator> reverse_iterator;

The type describes an object that can serve as a reverse bidirectional iterator for the controlled sequence.

multimap::size

size_type size() const noexcept;

The member function returns the length of the controlled sequence.

multimap::size_type

typedef typename Alloc::size_type size_type;

The unsigned integer type describes an object that can represent the length of any controlled sequence.

multimap::swap

void swap(multimap& right);

The member function swaps the controlled sequences between *this and right. If get_allocator() == right.get_allocator(), it does so in constant time, it throws an exception only as a result of copying the stored function object of type Pr, and it invalidates no references, pointers, or iterators that designate elements in the two controlled sequences. Otherwise, it performs a number of element assignments and constructor calls proportional to the number of elements in the two controlled sequences.

multimap::upper_bound

iterator upper_bound(const Key& keyval);
const_iterator upper_bound(const Key& keyval) const;

The member function returns an iterator that designates the earliest element right in the controlled sequence for which key_comp()(keyval, right.first) is true.

If no such element exists, the function returns end().

multimap::value_comp

value_compare value_comp() const;

The member function returns a function object that determines the order of elements in the controlled sequence.

multimap::value_compare

class value_compare
    : public binary_function<value_type, value_type,
        bool> {
public:
    bool operator()(const value_type& left,
        const value_type& right) const
        {return (comp(left.first, right.first)); }
protected:
    value_compare(key_compare pr)
        : comp(pr) {}
    key_compare comp;
    };

The type describes a function object that can compare the sort keys in two elements to determine their relative order in the controlled sequence. The function object stores an object comp of type key_compare. The member function operator() uses this object to compare the sort-key components of two element.

multimap::value_type

typedef pair<const Key, Ty> value_type;

The type describes an element of the controlled sequence.

operator!=

template<class Key, class Ty, class Pr, class Alloc>
    bool operator!=(
        const map <Key, Ty, Pr, Alloc>& left,
        const map <Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator!=(
        const multimap <Key, Ty, Pr, Alloc>& left,
        const multimap <Key, Ty, Pr, Alloc>& right);

The template function returns !(left == right).

operator==

template<class Key, class Ty, class Pr, class Alloc>
    bool operator==(
        const map <Key, Ty, Pr, Alloc>& left,
        const map <Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator==(
        const multimap <Key, Ty, Pr, Alloc>& left,
        const multimap <Key, Ty, Pr, Alloc>& right);

The first template function overloads operator== to compare two objects of template class map. The second template function overloads operator== to compare two objects of template class multimap. Both functions return left.size() == right.size() && equal(left. begin(), left. end(), right.begin()).

operator<

template<class Key, class Ty, class Pr, class Alloc>
    bool operator<(
        const map <Key, Ty, Pr, Alloc>& left,
        const map <Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator<(
        const multimap <Key, Ty, Pr, Alloc>& left,
        const multimap <Key, Ty, Pr, Alloc>& right);

The first template function overloads operator< to compare two objects of template class map. The second template function overloads operator< to compare two objects of template class multimap. Both functions return lexicographical_compare(left. begin(), left. end(), right.begin(), right.end(), left.value_comp()).

operator<=

template<class Key, class Ty, class Pr, class Alloc>
    bool operator<=(
        const map <Key, Ty, Pr, Alloc>& left,
        const map <Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator<=(
        const multimap <Key, Ty, Pr, Alloc>& left,
        const multimap <Key, Ty, Pr, Alloc>& right);

The template function returns !(right < left).

operator>

template<class Key, class Ty, class Pr, class Alloc>
    bool operator>(
        const map <Key, Ty, Pr, Alloc>& left,
        const map <Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator>(
        const multimap <Key, Ty, Pr, Alloc>& left,
        const multimap <Key, Ty, Pr, Alloc>& right);

The template function returns right < left.

operator>=

template<class Key, class Ty, class Pr, class Alloc>
    bool operator>=(
        const map <Key, Ty, Pr, Alloc>& left,
        const map <Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    bool operator!=(
        const multimap <Key, Ty, Pr, Alloc>& left,
        const multimap <Key, Ty, Pr, Alloc>& right);

The template function returns !(left < right).

swap

template<class Key, class Ty, class Pr, class Alloc>
    void swap(
        map <Key, Ty, Pr, Alloc>& left,
        map <Key, Ty, Pr, Alloc>& right);
template<class Key, class Ty, class Pr, class Alloc>
    void swap(
        multimap <Key, Ty, Pr, Alloc>& left,
        multimap <Key, Ty, Pr, Alloc>& right);

The template function executes left.swap(right).


See also the Table of Contents and the Index.

Copyright © 1992-2013 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.