std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::empty
来自 cppreference.cn
bool empty() const noexcept; |
(自 C++23 起) | |
检查底层容器是否为空。等效于: return begin() == end();。
内容 |
[编辑] 参数
(无)
[编辑] 返回值
true 如果底层容器为空,否则为 false。
[编辑] 复杂度
常数。
[编辑] 示例
以下代码使用 empty
来检查 std::flat_map<int, int> 是否包含任何元素
运行此代码
#include <iostream> #include <flat_map> #include <utility> int main() { std::flat_map<int,int> numbers; std::cout << std::boolalpha; std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n'; numbers.emplace(42, 13); numbers.insert(std::make_pair(13317, 123)); std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n'; }
输出
Initially, numbers.empty(): true After adding elements, numbers.empty(): false
[编辑] 参见
返回元素数量 (公开成员函数) | |
(C++17) |
检查容器是否为空 (函数模板) |