Map

map Associative Container

map is a kind of associative container (See Associative containers.) that supports unique keys (contains at most one of each key value) and provides for fast retrieval of values of another type T based on the keys. See Reversible Container.


template ,
          template  class Allocator = allocator>
class map { public:

// typedefs:
    typedef Key key_type;
    typedef pair value_type;
    typedef Compare key_compare;
    class value_compare
    : public binary_function {
        friend class map;
    protected:
        Compare comp;
        value_compare(Compare c) : comp(c) {}
    public:
        bool operator()(const value_type& x, const value_type& y) {
            return comp(x.first, y.first);
        }
    };
    typedef iterator;
    typedef const_iterator;
    typedef Allocator::pointer pointer;
    typedef Allocator::reference reference;
    typedef Allocator::const_reference const_reference;
    typedef size_type;
    typedef difference_type;
    typedef reverse_iterator;
    typedef const_reverse_iterator;

// allocation/deallocation:
    map(const Compare& comp = Compare());
    template 
    map(InputIterator first, InputIterator last,
        const Compare& comp = Compare());
    map(const map& x);
    ~map();
    map&
        operator=(const map& x);
    void swap(map& x);

// accessors:
    key_compare key_comp() const;
    value_compare value_comp() const;
    iterator begin();
    const_iterator begin() const;
    iterator end();
    const_iterator end() const;
    reverse_iterator rbegin();
    const_reverse_iterator rbegin();
    reverse_iterator rend();
    const_reverse_iterator rend();
    bool empty() const;
    size_type size() const;
    size_type max_size() const;
    Allocator::reference operator[](const key_type& x);

// insert/erase:
    pair insert(const value_type& x);
    iterator insert(iterator position, const value_type& x);
    template 
    void insert(InputIterator first, InputIterator last);
    void erase(iterator position);
    size_type erase(const key_type& x);
    void erase(iterator first, iterator last);

// map operations:
    iterator find(const key_type& x);
    const_iterator find(const key_type& x) const;
    size_type count(const key_type& x) const;
    iterator lower_bound(const key_type& x);
    const_iterator lower_bound(const key_type& x) const;
    iterator upper_bound(const key_type& x);
    const_iterator upper_bound(const key_type& x) const;
    pair equal_range(const key_type& x);
    pair equal_range(const key_type& x) const;
};

template 
bool operator==(const map& x,
                const map& y);

template 
bool operator<(const map& x,
               const map& y);

iterator Typedef on map

iterator is a bidirectional iterator referring to value_type. The exact type is implementation dependent and determined by Allocator.

const_iterator Typedef on map

const_iterator is a constant bidirectional iterator referring to const value_type. The exact type is implementation dependent and determined by Allocator. It is guaranteed that there is a constructor for const_iterator out of iterator.

size_type Typedef on map

size_type is an unsigned integral type. The exact type is implementation dependent and determined by Allocator.

difference_type Typedef on map

difference_type is a signed integral type. The exact type is implementation dependent and determined by Allocator.

[k] Operator on map

In addition to the standard set of member functions of associative containers, map provides Allocator<T>::reference operator[](const key_type&). For a map m and key k, m[k] is semantically equivalent to (*((m.insert(make_pair(k, T()))).first)).second.