我只是试图在Xcode5.0.2上使用c ++ 11的make_unique函数,Clang版本是
Apple LLVM 5.0版(clang-500.2.79)(基于LLVM 3.3svn)
检查后<memory>看起来它不存在.make_shared是.
我知道这是C++ 14,但它也是第一个为c ++ 14验证的函数之一.它甚至在Visual :)中.
它何时可用?
注意:注释多于答案,但格式化的代码和注释不会混淆.
不幸的是,不知道什么时候可用; 但是你现在可以自己轻松定义它,稍后再切换到标准版:
template <typename T, typename... Args>
auto make_unique(Args&&... args) -> std::unique_ptr<T>
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
Run Code Online (Sandbox Code Playgroud)
就是这样,与make_shared此处没有任何魔力相反,因为这种好处只是异常安全之一(将分配和捕获结合在一起unique_ptr),而make_shared捆绑了额外的优势(与之无关unique_ptr).