Question

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?

 46  28930  46
1 Jan 1970

Solution

 36

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. This did not happen. The first release to support Ranges in gcc was gcc 10.1.


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 at the time of writing 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).

2019-05-13

Solution

 14

Per Table 1.7. C++ 2020 Implementation Status

The One Ranges Proposal P0896R4

the version is 10.1. That means that you'll need to upgrade to at least that version to get the feature.

2019-05-13