名前空間
変種

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

提供: cppreference.com

[edit template]
 
 
 
 
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
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]