[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/memory/shared_ptr/allocate_shared [Back]  [Original]

std::allocate_shared, std::allocate_shared_for_overwrite cppreference.com
cppreference.com

std::allocate_shared, std::allocate_shared_for_overwrite

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
no section name
no section name
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)



no section name
 
 
<tbody> </tbody>
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[])
1) 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
2,3) , (1), , , , , , , std::allocator_traits<A2>::construct(a2, pv), a2 A2 std::remove_cv_t<std::remove_all_extents_t<T>>. (2) N . , , , .
4,5) , (2,3), 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 . , , , .
6) , (1), T , (3), T U[N], , .
7) , (2), , .

allocate_shared ( (2-5)) ( C++20) std::allocator_traits<A2>::destroy(a, p), p , a , allocate_shared, .

allocate_shared_for_overwrite ( , T ) p->~X(), p , X .

( C++20)

alloc Allocator.
args... , T.
N
u

std::shared_ptr T.

Alloc::allocate() T. , (1) . , . ( C++20)

std::make_shared, T, ( , , ). alloc , , .

std::shared_ptr , std::allocate_shared : T, .

std::shared_ptr ( C++17), std::allocate_shared . boost::allocate_shared.

( 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 -) []
,
( ) []

Web Proxy Viewer  |  New URL  |  Original Page