; map - C++ wiki
Learning Center
Plans & pricing Sign in
Sign Out
Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

map - C++ wiki


  • pg 1
									                               C++ : Reference : STL Containers : map                                                          login:                sign in

                               Search:                   Search                                                                    remember me     [register]


C Library
IOstream Library
Strings library
STL Containers
STL Algorithms

        STL Containers
map                      Source Code Review Tool Reduce Support Cost with Source Code Reviews. Download Trial Now! www2.SmartBear.com/30_Day_Trial
multiset                 C++ Database High Scalability, High Availability Large Data Sets, High Performance www.versant.com/objectdatabase
queue                    MapMogul Ltd Antique Maps Dealers in rare Maps and Atlases Fully illustrated web catalogue www.mapmogul.com
vector                   map                                                                                                                 class template
              map                                                                                                                                    <map>
comparison operators     Map
map::~map                Maps are a kind of associative containers that stores elements formed by the combination of a key value and a mapped value.
member functions:
— map::begin             In a map, the key value is generally used to uniquely identify the element, while the mapped value is some sort of value
— map::clear             associated to this key. Types of key and mapped value may differ. For example, a typical example of a map is a telephone guide
— map::count             where the name is the key and the telephone number is the mapped value.
— map::empty
— map::end               Internally, the elements in the map are sorted from lower to higher key value following a specific strict weak ordering criterion
— map::equal_range       set on construction.
— map::erase
— map::find              As associative containers, they are especially designed to be efficient accessing its elements by their key (unlike sequence
— map::get_allocator
                         containers, which are more efficient accessing elements by their relative or absolute position).
— map::insert
— map::key_comp
                         Therefore, the main characteristics of a map as an associative container are:
— map::lower_bound
— map::max_size
—   map::operator=           Unique key values: no two elements in the map have keys that compare equal to each other. For a similar associative
—   map::operator[]          container allowing for multiple elements with equivalent keys, see multimap.
—   map::rbegin              Each element is composed of a key and a mapped value. For a simpler associative container where the element value
—   map::rend                itself is its key, see set.
—   map::size                Elements follow a strict weak ordering at all times. Unordered associative arrays, like unordered_map, are available in
—   map::swap                implementations following TR1.
—   map::upper_bound
—   map::value_comp

                       Maps are also unique among associative containers in that they implement the direct access operator (operator[]) which allows
                       for direct access of the mapped value.

                       In their implementation in the C++ Standard Template Library, map containers take four template parameters:
                          1 template < class Key, class T, class Compare = less<Key>,
                          2             class Allocator = allocator<pair<const Key,T> > > class map;

                       Where the template parameters have the following meanings:

                             Key: Type of the key values. Each element in a map is uniquely identified by its key value.
                             T: Type of the mapped value. Each element in a map is used to store some data as its mapped value.
                             Compare: Comparison class: A class that takes two arguments of the key type and returns a bool. The expression
                             comp(a,b), where comp is an object of this comparison class and a and b are key values, shall return true if a is to be
                             placed at an earlier position than b in a strict weak ordering operation. This can either be a class implementing a function
                             call operator or a pointer to a function (see constructor for an example). This defaults to less<Key>, which returns the
                             same as applying the less-than operator (a<b).
                             The map object uses this expression to determine the position of the elements in the container. All elements in a map
                             container are ordered following this rule at all times.
                             Allocator: Type of the allocator object used to define the storage allocation model. By default, the allocator class
                             template is used, which defines the simplest memory allocation model and is value-independent.

                       In the reference for the map member functions, these same names (Key, T, Compare and Allocator) are assumed for the
                       template parameters.

                       This container class supports bidirectional iterators.
                       Iterators to elements of map containers access to both the key and the mapped value. For this, the class defines what is called its
                       value_type, which is a pair class with its first value corresponding to the const version of the key type (template parameter
                       Key) and its second value corresponding to the mapped value (template parameter T):
                            typedef pair<const Key, T> value_type;

                       Iterators of a map container point to elements of this value_type. Thus, for an iterator called it that points to an element of a
                       map, its key and mapped value can be accessed respectively with:
                          1 map<Key,T>::iterator it;
                          2 (*it).first;                   // the key value (of type Key)
                          3 (*it).second;                  // the mapped value (of type T)
                          4 (*it);                         // the "element value" (of type pair<const Key,T>)
Naturally, any other direct access operator, such as -> or [] can be used, for example:
  1 it->first;                      // same as (*it).first         (the key value)
  2 it->second;                     // same as (*it).second (the mapped value)

Member functions

(constructor)              Construct map (public member function)
(destructor)               Map destructor (public member function)
operator=                  Copy container content (public member function)

begin                      Return iterator to beginning (public member function)
end                        Return iterator to end (public member function)
rbegin                     Return reverse iterator to reverse beginning (public member function)
rend                       Return reverse iterator to reverse end (public member function)

empty                      Test whether container is empty (public member function)
size                       Return container size (public member function)
max_size                   Return maximum size (public member function)

Element access:
operator[]                 Access element (public member function)

insert                     Insert element (public member function)
erase                      Erase elements (public member function)
swap                       Swap content (public member function)
clear                      Clear content (public member function)

key_comp                Return key comparison object (public member function)
value_comp              Return value comparison object (public member function)

find                    Get iterator to element (public member function)
count                   Count elements with a specific key (public member function)
lower_bound             Return iterator to lower bound (public member function)
upper_bound             Return iterator to upper bound (public member function)
equal_range             Get range of equal elements (public member function)

get_allocator           Get allocator (public member function)

Member types
of template <class Key, class T, class Compare=less<Key>, class Allocator=allocator<pair <const Key, T> > >
class map;

     member type                                       definition
key_type               Key
mapped_type            T
value_type             pair<const Key,T>
key_compare            Compare
value_compare          Nested class to compare elements (see member function value_comp)
allocator_type         Allocator
reference              Allocator::reference
const_reference        Allocator::const_reference
iterator               Bidirectional iterator
const_iterator         Constant bidirectional iterator
size_type              Unsigned integral type (usually same as size_t)
difference_type        Signed integral type (usually same as ptrdiff_t)
pointer                Allocator::pointer
const_pointer          Allocator::const_pointer
reverse_iterator       reverse_iterator<iterator>
const_reverse_iterator reverse_iterator<const_iterator>
Awesomium™ Web Engine Embed Web Content in Your App With Awesomium™! Get The SDK Now. khrona.com/products/awesomium
Library Security Systems EM & RF systems; any library size checkin/out, rfid, labels, software www.librarysecurity.co.uk
MAPublisher Software Powerful Cartographic Software for making maps. Free evaluation. www.avenza.com

                                        Home page | Privacy policy
                          © cplusplus.com, 2000-2010 - All rights reserved - v2.3
                                       Spotted an error? contact us

To top