Do we have C++20 ranges library in GCC 9?
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).
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.
g++10 supports <ranges>
feature along with a number of other c++20 features.
#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::views::filter(even) | std::views::transform(square)) {
std::cout << i << ' ';
}
}
$ g++-10 -Wall -Wextra -std=c++20 ranges.cpp
$ ./a.out
0 4 16
On Ubuntu, the packages are now available. To install:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt install gcc-10 g++-10
However, g++-10 does not have support for all features. See the Table 1.8. C++ 2020 Library Features for features list supported.