std::shared_ptr<T>::operatorbool (3) - Linux Manuals
std::shared_ptr<T>::operatorbool: std::shared_ptr<T>::operatorbool
Command to display std::shared_ptr<T>::operatorbool
manual in Linux: $ man 3 std::shared_ptr<T>::operatorbool
NAME
std::shared_ptr<T>::operatorbool - std::shared_ptr<T>::operatorbool
Synopsis
explicit operator bool() const noexcept;
Checks if *this stores a non-null pointer, i.e. whether get() != nullptr.
Parameters
(none)
Return value
true if *this stores a pointer, false otherwise.
Notes
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.
Example
// 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);
}
Output:
ptr is not a valid pointer.
*ptr=7
See also
returns the stored pointer
get (public member function)
Pages related to std::shared_ptr<T>::operatorbool
- std::shared_ptr<T>::operator*,std::shared_ptr<T>::operator-> (3) - std::shared_ptr<T>::operator*,std::shared_ptr<T>::operator->
- std::shared_ptr<T>::operator<< (3) - std::shared_ptr<T>::operator<<
- std::shared_ptr<T>::operator= (3) - std::shared_ptr<T>::operator=
- std::shared_ptr<T>::operator==,!=,<,<=,>,>= (3) - std::shared_ptr<T>::operator==,!=,<,<=,>,>=
- std::shared_ptr<T>::operator[] (3) - std::shared_ptr<T>::operator[]
- std::shared_ptr<T>::owner_before (3) - std::shared_ptr<T>::owner_before
- std::shared_ptr<T>::get (3) - std::shared_ptr<T>::get
- std::shared_ptr<T>::reset (3) - std::shared_ptr<T>::reset
- std::shared_ptr<T>::shared_ptr (3) - std::shared_ptr<T>::shared_ptr
- std::shared_ptr<T>::swap (3) - std::shared_ptr<T>::swap
- std::shared_ptr<T>::unique (3) - std::shared_ptr<T>::unique
- std::shared_ptr<T>::use_count (3) - std::shared_ptr<T>::use_count
- std::shared_ptr<T>::~shared_ptr (3) - std::shared_ptr<T>::~shared_ptr
- std::shared_ptr (3) - std::shared_ptr
- std::shared_future (3) - std::shared_future
- std::shared_future<T>::get (3) - std::shared_future<T>::get