std::shared_ptr に対する推定ガイド
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <memory> で定義
|
||
template <class T> shared_ptr(std::weak_ptr<T>) -> shared_ptr<T>; |
(1) | (C++17以上) |
template <class T, class D> shared_ptr(std::unique_ptr<T, D>) -> shared_ptr<T>; |
(2) | (C++17以上) |
暗黙の推定ガイドでカバーされないエッジケースに対処するため、 std::shared_ptr に対してこれらの推定ガイドが提供されます。
配列形式の new と非配列形式の new のいずれから取得されたポインタか区別できないため、ポインタ型からのクラステンプレート引数推定はありません。
例
Run this code
#include <memory>
int main()
{
auto p = std::make_shared<int>(42);
std::weak_ptr w{p}; // explicit deduction guide is used in this case
std::shared_ptr p2{w}; // explicit deduction guide is used in this case
}