std::make_unique
標準 C++11 ライブラリに関数テンプレートがないのはなぜですか? 私は見つける
std::unique_ptr<SomeUserDefinedType> p(new SomeUserDefinedType(1, 2, 3));
少し冗長です。次のほうがずっといいと思いませんか?
auto p = std::make_unique<SomeUserDefinedType>(1, 2, 3);
これにより、 がnew
適切に非表示になり、タイプが 1 回だけ言及されます。
とにかく、これが私の実装の試みですmake_unique
:
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
コンパイルするのにかなり時間がかかりましたが、std::forward
それが正しいかどうかはわかりません。それは...ですか?とはstd::forward<Args>(args)...
どういう意味ですか? コンパイラはそれから何を作りますか?