public member function
<array>

std::array::empty

constexpr bool empty() noexcept;
Test whether array is empty
Returns a bool value indicating whether the array container is empty, i.e. whether its size is 0.

This function does not modify the content of the array in any way. To clear the content of an array object, use array::fill.

Parameters

none

Return Value

true if the array size is 0, false otherwise.
This is a constexpr.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// array::empty
#include <iostream>
#include <array>

int main ()
{
  std::array<int,0> first;
  std::array<int,5> second;
  std::cout << "first " << (first.empty() ? "is empty" : "is not empty") << '\n';
  std::cout << "second " << (second.empty() ? "is empty" : "is not empty") << '\n';
  return 0;
}


Output:
first is empty
second is not empty

Complexity

Constant.

Iterator validity

No changes.

Data races

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