std::experi...ointer_cast,(3)
π NAME π
okay so this is the std::experi...ointer_cast,(3) page from the C++ Standard Libary manual β yes, Libary is exactly how itβs spelled on the page, no cap. Itβs the library-fundamentals-TS pointer-cast girlies, and the NAME section is literally:
std::experimental::static_pointer_cast,std::experimental::dynamic_pointer_cast,
-
std::experimental::static_pointer_cast,std::experimental::dynamic_pointer_cast,
πΈ Synopsis πΈ
Four overloads, every one of them (library fundamentals TS) and noexcept. Here they are, signature by signature:
(1) β (library fundamentals TS)
template< class T, class U >
std::experimental::shared_ptr<T> static_pointer_cast( const std::experimental::shared_ptr<U>& r ) noexcept;
(2) β (library fundamentals TS)
template< class T, class U >
std::experimental::shared_ptr<T> dynamic_pointer_cast( const std::experimental::shared_ptr<U>& r ) noexcept;
(3) β (library fundamentals TS)
template< class T, class U >
std::experimental::shared_ptr<T> const_pointer_cast( const std::experimental::shared_ptr<U>& r ) noexcept;
(4) β (library fundamentals TS)
template< class T, class U >
std::experimental::shared_ptr<T> reinterpret_pointer_cast( const std::experimental::shared_ptr<U>& r ) noexcept;
okay so what do they actually do? They create a new instance of std::experimental::shared_ptr whose stored pointer is obtained from rβs stored pointer using a cast expression. If r is empty, so is the new shared_ptr (but its stored pointer is not necessarily null). π«Ά
Otherwise, the new shared_ptr will share ownership with r, except that it is empty if the dynamic_cast performed by dynamic_pointer_cast returns a null pointer.
Let Y be typename std::experimental::shared_ptr<T>::element_type, then the resulting std::experimental::shared_ptrβs stored pointer will be obtained by calling (in respective order):
static_cast<Y*>(r.get()).dynamic_cast<Y*>(r.get())(if the result of thedynamic_castis a null pointer value, the returnedshared_ptrwill be empty).const_cast<Y*>(r.get()).reinterpret_cast<Y*>(r.get()).
π¨ undefined behavior alert, bestie π¨ The behavior of these functions is undefined unless the corresponding cast fromU*toT*is well formed:
- The behavior is undefined unless
static_cast<T*>((U*)nullptr)is well formed. - The behavior is undefined unless
dynamic_cast<T*>((U*)nullptr)is well formed. - The behavior is undefined unless
const_cast<T*>((U*)nullptr)is well formed. - The behavior is undefined unless
reinterpret_cast<T*>((U*)nullptr)is well formed.
π Parameters π
rβ the pointer to convert
π Example π
This section is incomplete. Reason: no example π
π¦ See also π¦
constructorβ constructs newshared_ptr(public member function)static_pointer_castdynamic_pointer_castconst_pointer_castreinterpret_pointer_cast(function template)(C++17)- and the pointer-cast functions apply
static_cast,dynamic_cast,const_cast, orreinterpret_castto the stored pointer
π Categories: π
Noindexed pagesTodo no example
Source/version/date, bestie: http://cppreference.com, 2024.06.10, and the page is std::experi...ointer_cast,(3). Mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms