命名空间
变体
操作

std::array<T,N>::empty

来自 cppreference.cn
< cpp‎ | 容器‎ | array
 
 
 
 
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)
检查容器是否为空
(函数模板) [编辑]