Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

shared_ptr::operator boolean-type

Tests if an owned resource exists.

operator boolean-type() const;

The operator returns a value of a type that is convertible to bool. The result of the conversion to bool is true when get() != 0, otherwise false.

 

// std_tr1__memory__shared_ptr_operator_bool.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
int main() 
    { 
    std::shared_ptr<int> sp0; 
    std::shared_ptr<int> sp1(new int(5)); 
 
    std::cout << "(bool)sp0 == " << std::boolalpha 
        << (bool)sp0 << std::endl; 
    std::cout << "(bool)sp1 == " << std::boolalpha 
        << (bool)sp1 << std::endl; 
 
    return (0); 
    } 
 
(bool)sp0 == false
(bool)sp1 == true

Header: <memory>

Namespace: std

Show:
© 2015 Microsoft