clang 6.0.0版:clang ++"没有名为' make_optional'在命名空间' std' "

时间:2018-06-11 16:46:17

标签: c++17 optional clang++ gcc7

直到现在我一直在使用gcc在Ubuntu 16.04服务器版中编译我的C ++代码。但是由于C ++ 17的最新功能(主要是并发性和并行性)并没有被最新的gcc所限制,而在其中很多都是,我已经开始使用clang了。让我感到惊讶的是,对于之前使用gcc调试的C ++文件之一,在使用gcc编译时:gcc版本7.3.0(Ubuntu 7.3.0-21ubuntu1~16.04)执行正常,如果编译clang:clang版本6.0.0(标签/ RELEASE_600 / final),编译说错误:没有名为' make_optional'在命名空间' std' :

`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>

任何想法为什么铿锵说&#34;没有名为&#39; make_optional&#39;在命名空间&#39; std&#39; &#34;

1 个答案:

答案 0 :(得分:2)

<experimental/optional>将内容置于std::experimental命名空间中。这就是make_optional生活的地方。 -lc++experimental的使用并不意味着std::experimental的内容被转储到std命名空间。