Namespaces
Variants

std::vector<T,Allocator>::empty

cppreference.net에서

 
 
 
 
bool empty() const;
(C++11부터 noexcept)
(C++20부터 constexpr)

컨테이너에 요소가 없는지, 즉 begin() == end()인지 확인합니다.

반환값

true 컨테이너가 비어 있는 경우, false 그렇지 않은 경우.

복잡도

상수.

예제

#include <iostream>
#include <vector>
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

참고 항목

요소의 개수를 반환합니다
(public member function)
(C++17)
컨테이너가 비어 있는지 확인합니다
(function template)