std::array<T,N>::empty
来自cppreference.com
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) |
检查容器是否为空 (函数模板) |