名前空間
変種
操作

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

提供: cppreference.com
< cpp‎ | container‎ | array
 
 
 
 
constexpr bool empty() const noexcept;
(C++11以上)
(C++20未満)
[[nodiscard]] constexpr bool empty() const noexcept;
(C++20以上)

コンテナの持っている要素が無い、つまり 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

関連項目

要素数を返します
(パブリックメンバ関数) [edit]