名前空間
変種
操作

std::shared_ptr に対する推定ガイド

提供: cppreference.com
< cpp‎ | memory‎ | shared ptr
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
動的メモリ管理
スマートポインタ
(C++11)
(C++11)
(C++11)
(C++17未満)
(C++11)
アロケータ
メモリリソース
未初期化記憶域
ガベージコレクションサポート
その他
(C++20)
(C++11)
(C++11)
C のライブラリ
低水準のメモリ管理
 
 
ヘッダ <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 のいずれから取得されたポインタか区別できないため、ポインタ型からのクラステンプレート引数推定はありません。

[編集]

#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
}