std::flat_multiset<Key,Compare,KeyContainer>::empty
来自 cppreference.cn
< cpp | 容器 | flat multiset
bool empty() const noexcept; |
(C++23 起) | |
检查底层容器是否没有元素。等价于:return begin() == end();。
目录 |
[编辑] 参数
(无)
[编辑] 返回值
如果底层容器为空,则为true,否则为false。
[编辑] 复杂度
常数时间。
[编辑] 示例
以下代码使用 empty
来检查 std::flat_multiset<int> 是否包含任何元素
运行此代码
#include <iostream> #include <flat_set> int main() { std::flat_multiset<int> numbers; std::cout << std::boolalpha; std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n'; numbers.insert(42); numbers.insert(19937); std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n'; }
输出
Initially, numbers.empty(): true After adding elements, numbers.empty(): false
[编辑] 参阅
返回元素数量 (public member function) | |
(C++17) |
检查容器是否为空 (function template) |