【问题标题】:ranges::subrange in MSVC on Compiler Explorer编译器资源管理器上 MSVC 中的范围::子范围
【发布时间】:2021-02-12 17:57:51
【问题描述】:

下面的代码编译并运行得很好with GCC 8.3Clang 10.0.1,而它却惨败on MicroSoft shiny compiler

#include <vector>
#include <range/v3/view/group_by.hpp>

int main(){
    std::vector<int> edits{1,1,3,2,2,4,4,4,4,1,1,3,3,2};
    auto xxx = ranges::subrange(edits.begin(), edits.end());
}

我缺少一些标志吗?

【问题讨论】:

  • 它适用于/std:c++latest
  • 范围不是 c++17 的一部分。

标签: c++ visual-studio c++17 range-v3 compiler-explorer


【解决方案1】:

您已指定 /std:c++17ranges::subrange is not present in C++ 17。 Ranges-v3 还需要 C++ 20,因为它使用概念。

使用/std:c++latest 编译成功。

这些错误原来是来自 Ranges v3 中捆绑的概念仿真层,它显然不能在最新的 Visual C++ 的 C++17 模式下正常工作。根据文档,即使它确实可以工作,它也需要实验性的编译器选项,因此最好在使用 Microsoft 的编译器时打开 C++ 20 支持。

【讨论】:

  • 我可能误解了你的回答。显然std::ranges::whatever 带有 C++20,而不是 C++17,但我在示例中使用的是 Range-v3 库,而不是 C++20 范围库,它在 C++17 中确实有效。尽管如此,您使用/std:c++latest 的建议可以解决此问题。你能再解释一下吗?
  • 您的意思是 #include &lt;range/v3/view/group_by.hpp&gt; 正在处理,因为它是 #include &lt;ranges&gt;???
  • 为什么其他两个编译器和-std=c++17 一样好?
  • @Enlico:也许 Ranges v3 中包含的 concepts/concepts.hpp 标头在那些编译器上没有损坏?也许那些编译器在 C++17 模式下启用了太多功能?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-05
  • 2016-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-18
相关资源
最近更新 更多