Namespaces
Variants

std::any:: has_value

From cppreference.net
Utilities library
bool has_value ( ) const noexcept ;
(C++17부터)

객체가 값을 포함하는지 여부를 확인합니다.

목차

매개변수

(없음)

반환값

true 인스턴스가 값을 포함하는 경우에만 참입니다.

예제

#include <any>
#include <cassert>
#include <string>
int main()
{
    std::any a0;
    assert(a0.has_value() == false);
    std::any a1 = 42;
    assert(a1.has_value() == true);
    assert(std::any_cast<int>(a1) == 42);
    a1.reset();
    assert(a1.has_value() == false);
    auto a2 = std::make_any<std::string>("Andromeda");
    assert(a2.has_value() == true);
    assert(std::any_cast<std::string&>(a2) == "Andromeda");
    a2.reset();
    assert(a2.has_value() == false);
}

참고 항목

포함된 객체를 파괴함
(public member function)