C++ feature

Regarding C++ 20 Ranges Library,
Will the C++ Ranges code compile with Visual Studio C++ 2019,
Microsoft's latest compiler, using experimental include paths?

Will the above compiler using experimental path compile the following code?

#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 << ' ';
}
}

Above code has to give following output results i.e squares of even #s of the ints array:

0 4 16

If the above Microsoft Compiler can't compile the above code, is there any other latest C++ compiler that compiles this code?



Last edited on
From what I can tell, GCC and CLang may support this (and Visual Studio can be configured to use CLang easily), but not Microsoft's compiler at this point.
Microsoft is approx. 4 years behind standard.

Currently not even C++17 is fully supported.
You can take a look what features are being currently supported here:
https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=vs-2019
Thank you very much both Niccolo and malibor for the very useful information.
Best regards

I have downloaded and installed Windows installer exe file of Clang 8.0.0 C++ compiler.

Created Hello World C++ program using iostream include file.

Tried to compile using Clang++ command.

It gave error saying, Microsoft Visual Studio C++ is not found.

So, I bought Microsoft Visual Studio C++ 2019 Professional for $500 and installed.

Then above mentioned Hello World C++ program compiled and ran.

Then compiled following C++ ranges program using following command and it gave compile error:


C:>clang++ -Wall -std=c++2a cpp_ranges_even_odd.cpp -o cpp_ranges_even_odd.exe

cpp_ranges_even_odd.cpp:2:10: fatal error: 'ranges' file not found

#include <ranges>
         ^~~~~~~~
1 error generated.
C:>



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#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 << ' ';
}
}


Above compilation error is saying include file <ranges> is not found.

Anyone else compiled a C++ 20 ranges feature program using Clang++ 8.0.0?

I did not find a GCC compiler Windows installer exe for downloading. Any such link please?

Any ideas how to fix above compilation error please?

Best regards,



Can anyone compile above C++ ranges program using any of the following compilers?
Clan++ 8.0.0 compiler
Or GCC's g++ 9.1.0 compiler?

i.e. Is C++ standard 20 Ranges features supported by these compilers?

Thanks,
The standard is too early for anything other than experimental implementation, even in GCC.

What you can do is use this:

https://github.com/ericniebler/range-v3

It is made to work on several C++17 compliant compilers, and is what the C++ 20 standard is based upon.
What eagerness to get their hands on new C++20 features and make bugs with them. I hope you have understood well the old ones first ;-)

Microsoft is gradually introducing the new standard into the their product. If you ask me - too fast. Some people spend more time reporting bugs than writing code.

https://devblogs.microsoft.com/cppblog/cpp17-20-features-and-fixes-in-vs-2019/

The use of Ranges library I don't see to be support by any compiler here:
https://en.cppreference.com/w/cpp/compiler_support

Look the "The One Ranges Proposal" in above page - red everywhere.

I really recommend you first to wait major players to introduce something in their compilers, next to lose your time on it.

Last edited on
Topic archived. No new replies allowed.