Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

c++ - Do we have C++20 ranges library in GCC 9?

Do we have support for C++20 ranges library in the newly released GCC 9?

I copied the example code below for ranges library from: https://en.cppreference.com/w/cpp/ranges

#include <vector>
#include <ranges>
#include <iostream>

int main()
{
  std::vector<int> ints{0,1,2,3,4,5};
  auto even = [](int i){ return 0 == i % 2; };
  auto square = [](int i) { return i * i; };

  for (int i : ints | std::view::filter(even) | std::view::transform(square)) {
    std::cout << i << ' ';
  }
}

But when compiled with g++ 9.1 (Ubuntu 18.04 LTS (Bionic Beaver)), it complains that <ranges> cannot be found:

$ g++ -std=c++2a cpp2a.cpp 
cpp2a.cpp:2:10: fatal error: ranges: No such file or directory
    2 | #include <ranges>
      |          ^~~~~~~~
compilation terminated.

Am I missing something?

And will the ranges library arrive at some point of time with the GCC 9 series?

question from:https://stackoverflow.com/questions/56118941/do-we-have-c20-ranges-library-in-gcc-9

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Am I missing something?

No.

And will the ranges library arrive at some point of time with the gcc-9 series?

It's possible but seems unlikely.


Ranges is an enormous library. It's still 2019, the official C++20 standard still won't even be shipped for another year and a half. It'll take a while for it to get implemented in the major standard library implementations. We'll just have to wait.

If you want to start using Ranges, you can use Range-v3 (specifically the v1.0-beta branch) or you can find an implementation of C++20 Ranges at cmcstl2 (this is Casey Mysterious Carter's implementation).

You can also periodically check cppreference's compiler/library tracking page (which unsurprisingly currently shows no libraries having implemented the One Ranges proposal, but nevertheless does show quite a few C++20 features as having been implemented by the various library vendors).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...