Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

gcc

c++20

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?

like image 951
thor Avatar asked May 13 '19 19:05

thor


People also ask

Does G ++ 9 support C ++ 20?

C++20 features are available since GCC 8. "For G++ 9 and later" should be "For G++ 9 and earlier".

Does GCC 9 support C ++ 17?

GCC has had complete support for C++17 language features since version 8.

What are C ++ 20 ranges?

ranges::range. (C++20) specifies that a type is a range, that is, it provides a begin iterator and an end sentinel. (concept)

What version of GCC supports C ++ 11?

Status of Experimental C++11 Support in GCC 4.8 GCC provides experimental support for the 2011 ISO C++ standard. This support can be enabled with the -std=c++11 or -std=gnu++11 compiler options; the former disables GNU extensions.


1 Answers

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).

like image 91
Barry Avatar answered Oct 13 '22 12:10

Barry