std::array<T,N>::empty - cppreference.com
提供: cppreference.com
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
|
|
(C++11以上) (C++20未満) |
|
|
|
(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