std::allocate_shared, std::allocate_shared_for_overwrite
template< class T, class Alloc, class... Args > shared_ptr<T> allocate_shared( const Alloc& alloc, Args&&... args ); |
(1) | ( C++11) (T ) |
template< class T, class Alloc > shared_ptr<T> allocate_shared( const Alloc& alloc, std::size_t N ); |
(2) | ( C++20) (T U[]) |
template< class T, class Alloc > shared_ptr<T> allocate_shared( const Alloc& alloc ); |
(3) | ( C++20) (T U[N]) |
template< class T, class Alloc > shared_ptr<T> allocate_shared( const Alloc& alloc, std::size_t N, const std::remove_extent_t<T>& u ); |
(4) | ( C++20) (T U[]) |
template< class T, class Alloc > shared_ptr<T> allocate_shared( const Alloc& alloc, const std::remove_extent_t<T>& u ); |
(5) | ( C++20) (T U[N]) |
template< class T, class Alloc > shared_ptr<T> allocate_shared_for_overwrite( const Alloc& alloc ); |
(6) | ( C++20) (T U[]) |
template< class T, class Alloc > shared_ptr<T> allocate_shared_for_overwrite( const Alloc& alloc, std::size_t N ); |
(7) | ( C++20) (T U[]) |
T std::shared_ptr, args T. ::new (pv) T(v) ( C++20)std::allocator_traits<A2>::construct(a, pv, v) ( C++20), pv void* T, a , std::remove_cv_t<T>. , sizeof(T), , T. std::shared_ptr, , shared_from_this T. alloc, Allocator. , T std::allocator_traits<A2>::construct(a2, pv), a2 A2 std::remove_cv_t<std::remove_all_extents_t<T>>. (2) N . , , , .u. std::remove_extent_t<T> , , , (1), , std::remove_cv_t<std::remove_all_extents_t<T>>. , (, ), , u , (1), , std::remove_cv_t<std::remove_all_extents_t<T>>. (4) N . , , , . allocate_shared ( (2-5)) ( C++20) std::allocator_traits<A2>::destroy(a, p), p , a , allocate_shared, .
|
|
( C++20) |
| alloc | Allocator. | |
| args... | , T.
| |
| N | ||
| u |
Alloc::allocate() T. , (1) . , . ( C++20)
std::make_shared, T, ( , , ). alloc , , .
std::shared_ptr , std::allocate_shared : T, .
|
std::shared_ptr ( C++17), |
( C++20) |
shared_from_this ptr U* , , U ( C++17) , std::enable_shared_from_this, , :
if (ptr != nullptr && ptr->weak_this.expired())
ptr->weak_this = std::shared_ptr<std::remove_cv_t<U>>(
*this, const_cast<std::remove_cv_t<U>*>(ptr));
weak_this mutable std::weak_ptr std::enable_shared_from_this. weak_this . , shared_from_this() std::shared_ptr, .
ptr->weak_this.expired() , weak_this , . C++17.
__cpp_lib_smart_ptr_for_overwrite |
202002L |
(C++20) | (std::allocate_shared_for_overwrite, std::make_shared_for_overwrite, std::make_unique_for_overwrite); (6,7)
|
| : |
shared_ptr (public -) | |
| , ( ) |