Namespaces
Variants

std::unique_ptr<T,Deleter>:: operator bool

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
explicit operator bool ( ) const noexcept ;
(C++11부터)
(C++23부터 constexpr)

* this 가 객체를 소유하는지 여부를 확인합니다. 즉, get() != nullptr 인지 여부를 확인합니다.

목차

매개변수

(없음)

반환값

true 만약 * this 가 객체를 소유하고 있다면, false 그렇지 않은 경우.

예제

#include <iostream>
#include <memory>
int main()
{
    std::unique_ptr<int> ptr(new int(42));
    if (ptr)
        std::cout << "before reset, ptr is: " << *ptr << '\n';
    ptr.reset();
    (ptr ? (std::cout << "after reset, ptr is: " << *ptr)
        : (std::cout << "after reset ptr is empty")) << '\n';
}

출력:

before reset, ptr is: 42
after reset ptr is empty

참고 항목

관리되는 객체에 대한 포인터를 반환합니다
(public member function)