![]()
|
ALINK="#ff0000">
![]() multimap<Key, Data, Compare, Alloc>
DescriptionMultimap is a Sorted Associative Container that associates objects of type Key with objects of type Data. multimap is a Pair Associative Container, meaning that its value type is pair<const Key, Data>. It is also a Multiple Associative Container, meaning that there is no limit on the number of elements with the same key.Multimap has the important property that inserting a new element into a multimap does not invalidate iterators that point to existing elements. Erasing an element from a multimap also does not invalidate any iterators, except, of course, for iterators that actually point to the element that is being erased. Examplestruct ltstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; } }; int main() { multimap<const char*, int, ltstr> m; m.insert(pair<const char* const, int>("a", 1)); m.insert(pair<const char* const, int>("c", 2)); m.insert(pair<const char* const, int>("b", 3)); m.insert(pair<const char* const, int>("b", 4)); m.insert(pair<const char* const, int>("a", 5)); m.insert(pair<const char* const, int>("b", 6)); cout << "Number of elements with key a: " << m.count("a") << endl; cout << "Number of elements with key b: " << m.count("b") << endl; cout << "Number of elements with key c: " << m.count("c") << endl; cout << "Elements in m: " << endl; for (multimap<const char*, int, ltstr>::iterator it = m.begin(); it != m.end(); ++it) cout << " [" << (*it).first << ", " << (*it).second << "]" << endl; } DefinitionDefined in the standard header map, and in the nonstandard backward-compatibility header multimap.h.Template parameters
Model ofMultiple Sorted Associative Container, Pair Associative ContainerType requirements
Public base classesNone.Members
New membersAll of multimap's members are defined in the Multiple Sorted Associative Container and Pair Associative Container requirements. Multimap does not introduce any new members.Notes[1] Multimap::iterator is not a mutable iterator, because multimap::value_type is not Assignable. That is, if i is of type multimap::iterator and p is of type multimap::value_type, then *i = p is not a valid expression. However, multimap::iterator isn't a constant iterator either, because it can be used to modify the object that it points to. Using the same notation as above, (*i).second = p is a valid expression. The same point applies to multimap::reverse_iterator. [2] This member function relies on member template functions, which at present (early 1998) are not supported by all compilers. If your compiler supports member templates, you can call this function with any type of input iterator. If your compiler does not yet support member templates, though, then the arguments must either be of type const value_type* or of type multimap::const_iterator. See alsoAssociative Container, Sorted Associative Container, Pair Associative Container, Multiple Sorted Associative Container, set, map multiset, hash_set, hash_map, hash_multiset, hash_multimap![]() ![]() Copyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
|