std::vector<T,Allocator>::empty
提供: cppreference.com
bool empty() const; |
(C++11未満) | |
bool empty() const noexcept; |
(C++11以上) (C++20未満) |
|
[[nodiscard]] bool empty() const noexcept; |
(C++20以上) | |
コンテナの持っている要素が無い、つまり begin() == end() かどうかを調べます。
引数
(なし)
戻り値
コンテナが空であれば true、そうでなければ false。
計算量
一定。
例
Run this code
#include <vector>
#include <iostream>
int main()
{
std::cout << std::boolalpha;
std::vector<int> numbers;
std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n';
numbers.push_back(42);
std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n';
}
出力:
Initially, numbers.empty(): true
After adding elements, numbers.empty(): false
関連項目
| 要素数を返します (パブリックメンバ関数) |