std::
forward_list::empty
公众成员函数 <forward_list>
bool empty() const noexcept;
测试容器是否为空
返回一个bool值,指示forward_list容器是否为空,即其大小是否为0。
此函数不会以任何方式修改容器的内容。要清除数组对象的内容,请参见forward_list::clear。
☲ 参数
-
none
☉ 返回值
如果容器大小为0则为True,否则为false。
☣ 示例
// 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
✥ 复杂度
常量
☣ 迭代器的有效性
不变
⇄ 数据竞争
容器被访问。
不访问所包含的元素:并发访问或修改它们是安全的。
☂ 异常安全性
No-throw保证:这个成员函数从不抛出异常。
🍄 另请参阅
forward_list::clear |
清除内容(公众成员函数) |
forward_list::remove |
删除具有特定值的元素(公众成员函数) |