std::array<T,N>:: 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::array
| Member types | |||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | |||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Helper classes | |||||||||||||||||||||||||||||||||||||||||||||||
| Deduction guides (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||
|
constexpr
bool
empty
(
)
const
noexcept
;
|
(自 C++11 起) | |
检查容器是否为空。
目录 |
返回值
true 表示容器为空, false 表示容器非空。
复杂度
常量。
示例
以下代码使用
empty
检查
std::array
是否包含任何元素:
运行此代码
#include <array> #include <iostream> int main() { std::array<int, 4> numbers{3, 1, 4, 1}; std::array<int, 0> no_numbers; std::cout << std::boolalpha; std::cout << "numbers.empty(): " << numbers.empty() << '\n'; std::cout << "no_numbers.empty(): " << no_numbers.empty() << '\n'; }
输出:
numbers.empty(): false no_numbers.empty(): true
另请参阅
|
返回元素数量
(公开成员函数) |
|
|
(C++17)
|
检查容器是否为空
(函数模板) |