public member function
<forward_list>

std::forward_list::empty

bool empty() const noexcept;
Test whether array is empty
返回一個boolvalue indicating whether the forward_list container is empty, i.e. whether its size is0.

This function does not modify the content of the container in any way. To clear the content of an array object, see forward_list::clear.

引數



返回值

true如果容器大小為0, false否則為 false。

示例

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

int main ()
{
  std::forward_list<int> first;
  std::forward_list<int> second = {20, 40, 80};
  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;
}

輸出
first is empty
second is not empty


複雜度

常量。

迭代器有效性

沒有變化。

資料競爭

訪問容器。
不訪問任何包含的元素:併發訪問或修改它們是安全的。

異常安全

無異常保證:此成員函式從不丟擲異常。

另見