C++ Unordered_multimap Library - clear() Function


Advertisements

Description

The C++ function std::unordered_multimap::clear() destroys the unordered_multimap by removing all elements and sets the size of unordered_multimap to zero.

Declaration

Following is the declaration for std::unordered_multimap::clear() function form std::unordered_map() header.

C++11

void clear() noexcept;

Parameters

None

Return value

None

Exceptions

This member function never throws exception.

Time complexity

Linear i.e. O(n)

Example

The following example shows the usage of std::unordered_multimap::clear() function.

#include <iostream>
#include <unordered_map>

using namespace std;

int main(void) {
   unordered_multimap<char, int> umm = {
            {'a', 1},
            {'b', 2},
            {'c', 3},
            {'d', 4},
            {'e', 5}
            };

   cout << "Initial size of unordered multimap = " << umm.size() << endl;

   umm.clear();

   cout << "Size of unordered multimap after clear operaion = " << umm.size()
        << endl;

   return 0;
}

Let us compile and run the above program, this will produce the following result −

Initial size of unordered multimap = 5
Size of unordered multimap after clear operaion = 0
unordered_map.htm
Advertisements