public member function
<map>

std::multimap::clear

void clear();
void clear() noexcept;
Clear content
Removes all elements from the multimap container (which are destroyed), leaving the container with a size of 0.

Parameters

none

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// multimap::clear
#include <iostream>
#include <map>

int main ()
{
  std::multimap<char,int> mymultimap;
  std::multimap<char,int>::iterator it;

  mymultimap.insert(std::pair<char,int>('b',80));
  mymultimap.insert(std::pair<char,int>('b',120));
  mymultimap.insert(std::pair<char,int>('q',360));

  std::cout << "mymultimap contains:\n";
  for (it=mymultimap.begin(); it!=mymultimap.end(); ++it)
    std::cout << (*it).first << " => " << (*it).second << '\n';

  mymultimap.clear();

  mymultimap.insert(std::pair<char,int>('a',11));
  mymultimap.insert(std::pair<char,int>('x',22));

  std::cout << "mymultimap contains:\n";
  for (it=mymultimap.begin(); it != mymultimap.end(); ++it)
    std::cout << (*it).first << " => " << (*it).second << '\n';

  return 0;
}


Output:
mymultimap contains:
b => 80
b => 120
q => 360
mymap contains:
a => 11
x => 22

Complexity

Linear in size (destructions).

Iterator validity

All iterators, pointers and references related to this container are invalidated.

Data races

The container is modified.
All contained elements are modified.

Exception safety

No-throw guarantee: this member function never throws exceptions.

See also

  • 9281021542 2018-02-20
  • 632231541 2018-02-20
  • 9751491540 2018-02-20
  • 8333621539 2018-02-20
  • 995001538 2018-02-20
  • 6477441537 2018-02-20
  • 511981536 2018-02-19
  • 2072881535 2018-02-19
  • 6024461534 2018-02-19
  • 7594061533 2018-02-19
  • 9311341532 2018-02-19
  • 4928331531 2018-02-19
  • 38561530 2018-02-19
  • 7776611529 2018-02-19
  • 3038041528 2018-02-19
  • 9566341527 2018-02-19
  • 3936031526 2018-02-19
  • 9531111525 2018-02-19
  • 291211524 2018-02-19
  • 8962001523 2018-02-19