'C++' std::empty

토스트·2025년 5월 3일

'C++' basic

목록 보기
26/35

<array>, <deque>, <flat_map>, <flat_set>, <forward_list>, <inplace_vector>, <iterator>, <list>, <map>, <regex>, <set>, <span>, <string>, <string_view>, <unordered_map>, <unordered_set>, <vector>

empty

C++17 ~

template<class C>
constexpr auto epmty(const C& c)->decltype(c.empty());

template<class T, std::size_t N>
constexpr bool empty(const T (&array)[N]) noexcept;

template<class E>
constexpr bool empty(std::initializer_list<E> il) noexcept;

: 주어진 범위가 비어있는지 확인합니다. 비어있으면 true, 비어있지 않으면 false를 반환합니다.

  • c : empty 멤버 함수가 있는 컨테이너 또는 뷰
  • array : 임의의 배열
  • il : 초기화 목록

<example>

#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> vec;

    cout << vec.empty();

    int a[50];

    cout << empty(a); // 가비지 데이터가 들어가서 false를 반환

    cout << empty({ 1, 2 });

    return 0;
}

결과값

0개의 댓글