function template
<memory>
std::allocate_shared
template <class T, class Alloc, class... Args> shared_ptr<T> allocate_shared (const Alloc& alloc, Args&&... args);
Allocate shared_ptr
This function uses alloc to allocate storage for the object. A similar function, make_shared uses
::new to allocate the storage instead.Parameters
- alloc
- An allocator object.
Alloc is a type for which allocator_traits is well defined. - args
- List of elements passed to T's constructor.
Args is a list of zero or more types.
Return Value
A shared_ptr object that owns and stores a pointer to a newly allocated object of type T.Example
|
|
Output:
*foo: 10 *bar: 20 *baz: 30 40
See also
- make_shared
- Make shared_ptr (function template)
- shared_ptr::shared_ptr
- Construct shared_ptr (public member function)
- shared_ptr::operator=
- shared_ptr assignment (public member function)
- allocator_traits
- Allocator traits (class template)