Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 604 Bytes

058-cpp17-lib-misc-weak-ptr.md

File metadata and controls

31 lines (24 loc) · 604 Bytes

shared_ptr::weak_type

C++17ではshared_ptrweak_typeというネストされた型名が追加された。これはshared_ptrに対するweak_ptrtypedef名となっている。

namespace std {

template < typename T >
class shared_ptr
{
    using weak_type = weak_ptr<T> ;
} ;

}

使い方

template < typename Shared_ptr >
void f( Shared_ptr sptr )
{
    // C++14
    auto wptr1 = std::weak_ptr<
                    typename Shared_ptr::element_type
                >( sptr ) ;

    // C++17
    auto wptr2 = typename Shared_ptr::weak_type( sptr ) ;
}