How to implement make_unique function in C++11? [duplicate]

Copied from make_unique and perfect forwarding (the same is given in Herb Sutter’s blog)

template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

If you need it in VC2012, see Is there a way to write make_unique() in VS2012?


Nevertheless, if the solution in sasha.sochka’s answer compiles with your compiler, I would go with that one. That is more elaborate and works with arrays as well.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)