std::shared_ptr::reset

void reset(); (1) (since C++11) template< class Y > void reset( Y* ptr ); (2) (since C++11) template< class Y, class Deleter > void reset( Y* ptr, Deleter d ); (3) (since C++11) template< class Y, class Deleter, class Alloc > void reset( Y* ptr, Deleter d, Alloc alloc ); (4) (since C++11) Replaces the managed object with an object pointed to by ptr. Optional deleter d can be supplied, which is later used to destroy the new object when no shared_ptr

std::shared_ptr::owner_before

template< class Y > bool owner_before( const shared_ptr<Y>& other) const; template< class Y > bool owner_before( const std::weak_ptr<Y>& other) const; Checks whether this shared_ptr precedes other in implementation defined owner-based (as opposed to value-based) order. The order is such that two smart pointers compare equivalent only if they are both empty or if they both own the same object, even if the values of the pointers obtained by get() are

std::shared_ptr::operators (&gt;=)

Compare two shared_ptr objects template < class T, class U > bool operator==( const shared_ptr<T>& lhs, const shared_ptr<U>& rhs ); (1) (since C++11) template< class T, class U > bool operator!=( const shared_ptr<T>& lhs, const shared_ptr<U>& rhs ); (2) (since C++11) template< class T, class U > bool operator<( const shared_ptr<T>& lhs, const shared_ptr<U>& rhs ); (3) (since C++11) templat

std::shared_ptr::operator&lt;&lt;

template <class T, class U, class V> basic_ostream<U, V>& operator<<(basic_ostream<U, V>& os, const shared_ptr<T>& ptr); Inserts a shared_ptr<T> into a std::basic_ostream. Equivalent to os << ptr.get(). Parameters os - a std::basic_ostream to insert ptr into ptr - the data to be inserted into os Return value os. Example #include <iostream> #include <memory> class Foo {}; int main() { a

std::shared_ptr::operator bool

explicit operator bool() const; 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. Exceptions noexcept specification: noexcept 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 #include <iostream> #include <memory> typedef std::shared_ptr&

std::shared_ptr::get

T* get() const; (since C++11) Returns a pointer to the managed object or a null pointer if no object is being managed. Parameters (none). Return value A pointer to the managed object or null. Exceptions noexcept specification: noexcept Example #include <iostream> #include <memory> #include <string> typedef std::shared_ptr<int> IntPtr; void output(const std::string& msg, int* pInt) { std::cout << msg << *pInt << "\n";

std::shared_ptr

Defined in header <memory> template< class T > class shared_ptr; (since C++11) std::shared_ptr is a smart pointer that retains shared ownership of an object through a pointer. Several shared_ptr objects may own the same object. The object is destroyed and its memory deallocated when either of the following happens: the last remaining shared_ptr owning the object is destroyed. the last remaining shared_ptr owning the object is assigned another pointer via operator=

std::shared_mutex::unlock_shared

void unlock_shared(); (since C++17) Releases the mutex from shared ownership by the calling thread. . The mutex must be locked by the current thread of execution in shared mode, otherwise, the behavior is undefined. This operation synchronizes-with (as defined in std::memory_order) any subsequent lock() operation that obtains ownership of the same mutex. Parameters (none). Return value (none). Exceptions (none). Notes unlock_shared() is usually not called directly: std::shar

std::shared_mutex::unlock

void unlock(); (since C++17) Unlocks the mutex. The mutex must be locked by the current thread of execution, otherwise, the behavior is undefined. This operation synchronizes-with (as defined in std::memory_order) any subsequent lock operation that obtains ownership of the same mutex. Parameters (none). Return value (none). Exceptions (none). Notes unlock() is usually not called directly: std::unique_lock and std::lock_guard are used to manage exclusive locking. Example

std::shared_mutex::try_lock_shared

bool try_lock_shared(); (since C++17) Tries to lock the mutex in shared mode. Returns immediately. On successful lock acquisition returns true, otherwise returns false. This function is allowed to fail spuriously and return false even if the mutex is not currenly exclusively locked by any other thread. Prior unlock() operation on the same mutex synchronizes-with (as defined in std::memory_order) this operation if it returns true. The behavior is undefined if the calling thread already o