GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::shared_ptr::operatorbool(3) C++ Standard Libary std::shared_ptr::operatorbool(3)

std::shared_ptr::operatorbool - std::shared_ptr::operatorbool


explicit operator bool() const noexcept;


Checks if *this stores a non-null pointer, i.e. whether get() != nullptr.


(none)


true if *this stores a pointer, false otherwise.


An empty shared_ptr (where use_count() == 0) may store a non-null pointer accessible
by get(), e.g. if it were created using the aliasing constructor.

// Run this code


#include <iostream>
#include <memory>


void report(std::shared_ptr<int> ptr)
{
if (ptr) {
std::cout << "*ptr=" << *ptr << "\n";
} else {
std::cout << "ptr is not a valid pointer.\n";
}
}


int main()
{
std::shared_ptr<int> ptr;
report(ptr);


ptr = std::make_shared<int>(7);
report(ptr);
}


ptr is not a valid pointer.
*ptr=7


get returns the stored pointer
(public member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.