std::array<T,N>::empty
ja.cppreference.net より
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
関連項目
|
要素数を返す
(public member function) |
|
|
(C++17)
|
コンテナが空かどうかをチェックする
(function template) |