名稱空間
變體
操作

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

來自 cppreference.com
< 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)
檢查容器是否為空
(函式模板) [編輯]