Namespaces
Variants

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

From cppreference.net

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

컨테이너에 요소가 없는지 확인합니다.

목차

반환값

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

복잡도

상수.

예제

다음 코드는 empty 를 사용하여 std:: forward_list < int > 가 요소를 포함하는지 확인합니다:

#include <forward_list>
#include <iostream>
int main()
{
    std::forward_list<int> numbers;
    std::cout << std::boolalpha;
    std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n';
    numbers.push_front(42);
    numbers.push_front(13317); 
    std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n';
}

출력:

Initially, numbers.empty(): true
After adding elements, numbers.empty(): false

참고 항목

두 반복자 사이의 거리를 반환합니다
(함수 템플릿)