到目前为止,我一直在使用 gcc 在 Ubuntu 16.04 服务器版中编译我的 C++ 代码。但是由于 C++17 的最新特性(主要是并发和并行)没有被最新的 gcc 转换,而在 clang 中很多是,我已经开始使用 clang。令我惊讶的是,对于以前 gcc 调试过的 C++ 文件之一,在使用 gcc 编译时:gcc 版本 7.3.0(Ubuntu 7.3.0-21ubuntu1~16.04),如果编译 clang:clang 版本 6.0.0( tags/RELEASE_600/final),编译显示错误:命名空间“std”中没有名为“make_optional”的成员:
`marco@PC:~/marcoTensor$ g++ -std=c++17 bigMatricesDiv01.cpp
-obigMatricesDiv01
marco@PC:~/marcoTensor$ ./bigMatricesDiv01
Timer MTensor::Tensor2D A = randU2<double>(20,400,2.7,4.6) : 154 ms
Timer MTensor::Tensor2D B = randN2<double>(20,400,3,2.6) :111 ms
Timer MTensor::Tensor2D ApB = A/B :0 ms
marco@PC:~/marcoTensor$ clang++ -std=c++17 -stdlib=libc++ -w -fcolor-
diagnostics bigMatricesDiv01.cpp -obigMatricesDiv01 -lc++experimental
In file included from bigMatricesDiv01.cpp:1:
In file included from ./tensorTypes.h:1:
In file included from ./MTensorUtils.h:1:
In file included from ./MTensor.h:5:
In file included from ./GeneralUtils.h:16:
./FunctionalApproach.h:953:27: error: no template named 'optional' in
namespace 'std'
auto transform(const std::optional<T1>& opt, F f) ->
decltype(std::make_optional(f(opt.value()))){
~~~~~^
./FunctionalApproach.h:953:68: error: no member named 'make_optional' in
namespace 'std'
auto transform(const std::optional<T1>& opt, F f) ->
decltype(std::make_optional(f(opt.value()))){
~~~~~^
./FunctionalApproach.h:955:17: error: no member named 'make_optional' in
namespace 'std'
return std::make_optional(f(opt.value()));
~~~~~^
3 errors generated.
` 但是:在 FunctionalApproach.h 中:
#include <experimental/propagate_const>
#include <experimental/optional>
知道为什么clang说“命名空间'std'中没有名为'make_optional'的成员”吗?