gpt4 book ai didi

c++ - Xcode5 中的 make_unique 可用性?

转载 作者:太空狗 更新时间:2023-10-29 20:42:06 26 4
gpt4 key购买 nike

我只是想在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com