std::out_ptr

From cppreference.com
< cpp‎ | memory‎ | out ptr t
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)
 
Dynamic memory management
Smart pointers
(C++11)
(C++11)
(C++11)
(until C++17)
(C++11)
(C++23)
Allocators
Memory resources
Uninitialized storage
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Garbage collection support
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
Miscellaneous
(C++20)
(C++11)
(C++11)
 
std::out_ptr_t
Member functions
Non-member functions
out_ptr
(C++23)
 
Defined in header <memory>
template< class Pointer = void, class Smart, class... Args >
auto out_ptr( Smart& s, Args&&... args );
(since C++23)

Returns an out_ptr_t with deduced template arguments that captures arguments for resetting by reference.

The program is ill-formed if construction of the return value (see below) is ill-formed.

Parameters

s - the object (typically a smart pointer) to adapt
args... - the arguments for resetting to capture

Return value

std::out_ptr_t<Smart, P, Args&&>(s, std::forward<Args>(args)...), where P is

  • Pointer, if Pointer is not same as void,
  • otherwise, Smart::pointer, if it is valid and denotes a type,
  • otherwise, Smart::element_type*, if Smart::element_type is valid and denotes a type,
  • otherwise, std::pointer_traits<Smart>::element_type*.

Notes

Users may specify the template argument for the template parameter Pointer, in order to interoperate with foreign functions that take a Pointer*.

As all arguments for resetting are captured by reference, the returned out_ptr_t should be a temporary object destroyed at the end of the full-expression containing the call to the foreign function, in order to avoid dangling references.

Feature-test macro: __cpp_lib_out_ptr

Example

See also

(C++23)
creates an inout_ptr_t with an associated smart pointer and resetting arguments
(function template)
creates a unique pointer that manages a new object
(function template)
creates a shared pointer that manages a new object
(function template)