最終更新日時(UTC):
が更新

履歴 編集

<memory>

std::weak_ptr::推論補助(C++17)

namespace std {
  template<class T>
  weak_ptr(shared_ptr<T>) -> weak_ptr<T>;
}

概要

std::shared_ptrからstd::weak_ptrに変換する際の、クラステンプレートの型推論補助。

#include <memory>
#include <type_traits>

int main()
{
  std::shared_ptr<int> sp {new int(3)};
  std::weak_ptr wp = sp;
  static_assert(std::is_same_v<
    decltype(wp),
    std::weak_ptr<int>
  >);
}

出力

バージョン

言語

  • C++17

処理系

関連項目

参照