如何在 clang 3.4 中使用 make_unique?
How to use make_unique in clang 3.4?
使用 Travis-CI
我正在尝试构建一个使用 std::make_unique
的 C++ 项目。但是我得到一个构建错误:
no member named 'make_unique' in namespace 'std'
mFiles.emplace_back(std::make_unique<File>(*this, rec));
我已经包含 memory
,此代码在 VS2013 和 gcc 4.8 中使用 -std=c++14
编译。如果我在 clang 3.4 中使用这个标志,我会得到一个错误:
error: invalid value 'c++14' in '-std=c++14'
根据 clang 文档:
http://clang.llvm.org/cxx_status.html
我应该使用 -std=c++1y
但这仍然产生相同的 no member named 'make_unique' in namespace 'std'
。那么我该如何让它发挥作用呢?
这不依赖于编译器,而是依赖于标准库的实现。 std::make_unique
不是核心语言特性,而是库函数。
检查 Travis 使用的 libstdc++
版本。
根据 the GCC 4.9 changelog,std::make_unique
在 GCC 4.9 发布前后被引入 libstdc++
。
如果 Travis 使用的是 4.9 之前的 GCC 版本,它的 libstdc++
版本很可能还没有 std::make_unique
。
使用 Travis-CI
我正在尝试构建一个使用 std::make_unique
的 C++ 项目。但是我得到一个构建错误:
no member named 'make_unique' in namespace 'std'
mFiles.emplace_back(std::make_unique<File>(*this, rec));
我已经包含 memory
,此代码在 VS2013 和 gcc 4.8 中使用 -std=c++14
编译。如果我在 clang 3.4 中使用这个标志,我会得到一个错误:
error: invalid value 'c++14' in '-std=c++14'
根据 clang 文档:
http://clang.llvm.org/cxx_status.html
我应该使用 -std=c++1y
但这仍然产生相同的 no member named 'make_unique' in namespace 'std'
。那么我该如何让它发挥作用呢?
这不依赖于编译器,而是依赖于标准库的实现。 std::make_unique
不是核心语言特性,而是库函数。
检查 Travis 使用的 libstdc++
版本。
根据 the GCC 4.9 changelog,std::make_unique
在 GCC 4.9 发布前后被引入 libstdc++
。
如果 Travis 使用的是 4.9 之前的 GCC 版本,它的 libstdc++
版本很可能还没有 std::make_unique
。