std::weak_ptr の推論ガイド
From cppreference.com
| ヘッダ <memory> で定義 |
||
| template< class T > weak_ptr( std::shared_ptr<T> ) -> weak_ptr<T>; |
(C++17以降) | |
暗黙的な推論ガイドで見落とされていたエッジケースに対応するため、std::weak_ptr には 1 つの推論ガイドが用意されています。
[編集] 例
このコードを実行
#include <memory> int main() { auto p = std::make_shared<int>(42); std::weak_ptr w{p}; // explicit deduction guide is used in this case }