std::vector<T,Allocator>:: empty
From cppreference.net
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::vector
| Member types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Deduction guides (C++17) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
bool
empty
(
)
const
;
|
(自 C++11 起为 noexcept)
(自 C++20 起为 constexpr) |
|
检查容器是否为空。
目录 |
返回值
true 表示容器为空, false 表示容器非空。
复杂度
常量。
示例
运行此代码
#include <iostream> #include <vector> int main() { std::cout << std::boolalpha; std::vector<int> numbers; std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n'; numbers.push_back(42); std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n'; }
输出:
Initially, numbers.empty(): true After adding elements, numbers.empty(): false
另请参阅
|
返回元素数量
(公开成员函数) |
|
|
(C++17)
|
检查容器是否为空
(函数模板) |