std::weak_ptr

Defined in header <memory> template< class T > class weak_ptr; (since C++11) std::weak_ptr is a smart pointer that holds a non-owning ("weak") reference to an object that is managed by std::shared_ptr. It must be converted to std::shared_ptr in order to access the referenced object. std::weak_ptr models temporary ownership: when an object needs to be accessed only if it exists, and it may be deleted at any time by someone else, std::weak_ptr is used to track the objec

std::weak_ptr::reset

void reset(); (since C++11) Releases the reference to the managed object. After the call *this manages no object. Parameters (none). Return value (none). Exceptions noexcept specification: noexcept

std::weak_ptr::lock

std::shared_ptr<T> lock() const; (since C++11) Creates a new std::shared_ptr that shares ownership of the managed object. If there is no managed object, i.e. *this is empty, then the returned shared_ptr also is empty. Effectively returns expired() ? shared_ptr<T>() : shared_ptr<T>(*this), executed atomically. Parameters (none). Return value A shared_ptr which shares ownership of the owned object. Exceptions noexcept specification: noexcept Notes Both this

std::weak_ptr::use_count

long use_count() const; (since C++11) Returns the number of shared_ptr instances that share ownership of the managed object, or ​0​ if the managed object has already been deleted, i.e. *this is empty. Parameters (none). Return value The number of shared_ptr instances sharing the ownership of the managed object. Exceptions noexcept specification: noexcept Notes expired() may be faster than use_count(). Example See also expired checks whether the referenced object

std::weak_ptr::owner_before

template< class Y > bool owner_before( const weak_ptr<Y>& other) const; template< class Y > bool owner_before( const std::shared_ptr<Y>& other) const; Checks whether this weak_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 d

std::weak_ptr::expired

bool expired() const; (since C++11) Checks whether the managed object has already been deleted. Equivalent to use_count() == 0. Parameters (none). Return value true if the managed object has already been deleted, false otherwise. Exceptions noexcept specification: noexcept Example Demonstrates how expired is used to check validity of the pointer. #include <iostream> #include <memory> std::weak_ptr<int> gw; void f() { if (!gw.expired()) {

std::wctomb

Defined in header <cstdlib> int wctomb( char *s, wchar_t wc ); Converts a wide character wc to multibyte encoding and stores it (including any shift sequences) in the char array whose first element is pointed to by s. No more than MB_CUR_MAX characters are stored. If wc is the null character, the null byte is written to s, preceded by any shift sequences necessary to restore the initial shift state. If s is a null pointer, resets the global conversion state and determines w

std::wctrans

Defined in header <cwctype> std::wctrans_t wctrans( const char* str ); Constructs a value of type std::wctrans_t that describes a LC_CTYPE category of wide character mapping. It may be one of the standard mappings, or a locale-specific mapping, such as "tojhira" or "tojkana". Parameters str - C string holding the name of the desired mapping. The following values of str are supported in all C locales: Value of str Effect "toupper" identifies the mapping used b

std::wctype

Defined in header <cwctype> std::wctype_t wctype( const char* str ); Constructs a value of type std::wctype_t that describes a LC_CTYPE category of wide character classification. It may be one of the standard classification categories, or a locale-specific category, such as "jkanji". Parameters str - C string holding the name of the desired category The following values of str are supported in all C locales: value of str effect "alnum" identifies the categ

std::wcsxfrm

Defined in header <cwchar> std::size_t strxfrm( wchar_t* dest, const wchar_t* src, std::size_t count ); Transforms the null-terminated wide string pointed to by src into the implementation-defined form such that comparing two transformed strings with std::wcscmp gives the same result as comparing the original strings with std::wcscoll, in the current C locale. The first count characters of the transformed string are written to destination, including the terminating null cha