Namespaces
Variants

std::basic_string_view<CharT,Traits>:: empty

From cppreference.net
constexpr bool empty ( ) const noexcept ;
(C++17부터)

뷰에 문자가 없는지 확인합니다. 즉, size() == 0 인지 여부를 확인합니다.

목차

매개변수

(없음)

반환값

true 뷰가 비어 있는 경우, false 그렇지 않은 경우.

복잡도

상수.

예제

#include <iostream>
#include <string_view>
// 작은따옴표로 둘러싼 문자열, 길이,
// 그리고 빈 문자열인지 여부를 출력합니다.
void check_string(std::string_view ref)
{
    std::cout << std::boolalpha
              << "'" << ref << "' has " << ref.size()
              << " character(s); emptiness: " << ref.empty() << '\n';
}
int main(int argc, char **argv)
{
    // 빈 문자열
    check_string("");
    // 거의 항상 비어있지 않음: argv[0]
    if (argc > 0)
        check_string(argv[0]);
}

가능한 출력:

'' has 0 character(s); emptiness: true
'./a.out' has 7 character(s); emptiness: false

참고 항목

문자의 수를 반환합니다
(public member function)
최대 문자 수를 반환합니다
(public member function)
(C++17) (C++20)
컨테이너나 배열의 크기를 반환합니다
(function template)
(C++17)
컨테이너가 비어 있는지 확인합니다
(function template)
문자열이 비어 있는지 확인합니다
( std::basic_string<CharT,Traits,Allocator> 의 public member function)