public member function
<map>

std::map::empty

bool empty() const;
bool empty() const noexcept;
Test whether container is empty
Returns whether the map container is empty (i.e. whether its size is 0).

This function does not modify the container in any way. To clear the content of a map container, see map::clear.

Parameters

none

Return Value

true if the container size is 0, false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// map::empty
#include <iostream>
#include <map>

int main ()
{
  std::map<char,int> mymap;

  mymap['a']=10;
  mymap['b']=20;
  mymap['c']=30;

  while (!mymap.empty())
  {
    std::cout << mymap.begin()->first << " => " << mymap.begin()->second << '\n';
    mymap.erase(mymap.begin());
  }

  return 0;
}

Output:
a => 10
b => 20
c => 30


Complexity

Constant.

Iterator validity

No changes.

Data races

The container is accessed.
No contained elements are accessed: concurrently accessing or modifying them is safe.

Exception safety

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

See also