std::pointe...::pointer_to(3)
π NAME π
std::pointer_traits::pointer_to β yes bestie, the name and the thing are both std::pointer_traits::pointer_to. This is the std::pointe...::pointer_to(3) page from the C++ Standard Libary, and it's literally all about constructing a dereferenceable pointer or pointer-like object. π«Ά
β¨ Synopsis β¨
Defined in header <memory>
static pointer pointer_to( element_type& r ); (1) (since C++11) (member of pointer_traits<Ptr> specialization)
static pointer pointer_to( element_type& r ) noexcept; (2) (since C++11) (until C++20) (member of pointer_traits<T*> specialization)
static constexpr pointer pointer_to( element_type& r ) noexcept; (2) (since C++20) (member of pointer_traits<T*> specialization)
okay so the whole vibe: it constructs a dereferenceable pointer or pointer-like object ("fancy pointer") to its argument. That's the main character energy of this page. π
Version (1) is the one in the non-specialized std::pointer_traits template. It simply calls Ptr::pointer_to(r), and if Ptr does not provide a static member function pointer_to, instantiation of this function is a compile-time error. Not me getting rejected at compile time ππ
Version (2) is the one in the specialization of std::pointer_traits for pointer types. It returns std::addressof(r). Slay. β¨
πΈ Parameters πΈ
rβ reference to an object of typeelement_type&, except ifelement_typeisvoid, in which case the type ofris unspecified.
π¦ Return value π¦
A dereferenceable pointer to r, of the type pointer_traits<>::pointer. Iconic. π
π Exceptions π
(1)Unspecified (typically same asPtr::pointer_to).
π§ Notes π§
The Boost.Intrusive library version of this function returns pointer(std::addressof(r)) if Ptr::pointer_to does not exist.
π See also π
addressof(C++11)β obtains actual address of an object, even if the&operator is overloaded (function template).address(until C++20)β obtains the address of an object, even ifoperator&is overloaded (public member function ofstd::allocator<T>).to_address[static](C++20)(optional)β obtains a raw pointer from a fancy pointer (inverse ofpointer_to) (public static member function).to_address(C++20)β obtains a raw pointer from a pointer-like type (function template).
okay that's the page, bestie! source/version + date sign-off: http://cppreference.com, dated 2024.06.10, and the footer is std::pointe...::pointer_to(3). byeee πβ¨π
π¦ 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