C++ Unordered_multimap Library - empty() Function



Description

The C++ function std::unordered_multimap::empty() tests whether unordered_multimap is empty or not. Unordered_multimap of size zero is considered as empty.

Declaration

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

C++11

bool empty() const noexcept;

Parameters

None

Return value

Returns true if unordered_multimap is empty otherwise false.

Exceptions

This member function never throws exception.

Time complexity

Constant i.e. O(1)

Example

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

#include <iostream>
#include <unordered_map>

using namespace std;

int main(void) {
   unordered_multimap<char, int> umm;

   if (umm.empty())
      cout << "Unordered multimap is empty." << endl;

   umm.emplace_hint(umm.begin(), 'a', 1);
   umm.emplace_hint(umm.end(), 'b', 2);

   if (!umm.empty())
      cout << "Unordered multimap is not empty." << endl;

   return 0;
}

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

Unordered multimap is empty.
Unordered multimap is not empty.
unordered_map.htm
Advertisements