Component type: type

Description

Multimap 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.

Example

struct 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;

}

Definition

Defined in the standard header map, and in the nonstandard backward-compatibility header multimap.h.

Template parameters
Parameter Description Default
Key The multimap's key type. This is also defined as multimap::key_type.
Data The multimap's data type. This is also defined as multimap::data_type.
Compare The key comparison function, a Strict Weak Ordering whose argument type is key_type; it returns true if its first argument is less than its second argument, and false otherwise. This is also defined as multimap::key_compare. less<Key>
Alloc The multimap 's allocator, used for all internal memory management. alloc
Model of

Multiple Sorted Associative Container, Pair Associative Container

Type requirements

• Data is Assignable.

• Compare is a Strict Weak Ordering whose argument type is Key.

• Alloc is an Allocator.

Public base classes

None.

Members
Member Where defined Description
key_type Associative Container The multimap 's key type, Key.
data_type Pair Associative Container The type of object associated with the keys.
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату