std::array<T,N>::empty
来自 zh.cppreference.net
constexpr bool empty() const noexcept;
|
(自C++11起) | |
检查容器是否没有元素,即是否 begin() == end().
返回值
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)
|
检查容器是否为空
(函数模板) |