【问题标题】:clang version 6.0.0 : clang++ "no member named 'make_optional' in namespace 'std' "clang 6.0.0 版:clang++“命名空间‘std’中没有名为‘make_optional’的成员”
【发布时间】:2018-11-20 23:42:37
【问题描述】:

到目前为止,我一直在使用 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' 的成员”吗?

【问题讨论】:

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


【解决方案1】:

&lt;experimental/optional&gt; 将事物放入 std::experimental 命名空间。这就是make_optional 生活的地方。使用-lc++experimental 并不意味着std::experimental 的内容被转储到std 命名空间中。

【讨论】:

    猜你喜欢
    • 2014-09-26
    • 1970-01-01
    • 2017-02-13
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多