我只是想在 Xcode5.0.2 上使用 c++11 的 make_unique 函数, Clang 版本是
Apple LLVM version 5.0 (clang-500.2.79) (based on 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)...));
}
就是这样,与make_shared
相反这里没有魔法,因为好处只是异常安全之一(在 unique_ptr
中将分配和捕获联系在一起),而 make_shared
捆绑了额外的优势(与 unique_ptr
无关)。
关于c++ - Xcode5 中的 make_unique 可用性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19996278/