public member function

std::array::empty

<array>
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" ) << std::endl;
  std::cout << "second " << (second.empty() ? "is empty" : "is not empty" ) << std::endl;
  return 0;
}


Output:
first is empty
second is not empty

Complexity

Constant.

Iterator validity

No changes.

See also