Namespaces
Variants

deduction guides for std::weak_ptr

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (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)
(C++11) (until C++23)
定義先ヘッダ <memory>
template < class T >
weak_ptr ( std:: shared_ptr < T > ) - > weak_ptr < T > ;
(C++17以降)

1つの 推論ガイド std::weak_ptr に対して提供されており、暗黙の推論ガイドで見逃されていたエッジケースを考慮しています。

#include <memory>
int main()
{
    auto p = std::make_shared<int>(42);
    std::weak_ptr w{p}; // このケースでは明示的なデダクションガイドが使用される
}