I am testing ranges from C++ 20 , and this is my main.cpp
:
#include <ranges>
#include <iostream>
int main()
{
auto const 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 << ' ';
}
std::cout << '\n';
}
To compile it with clang++-12
but it couldn't find 'ranges':
$ clang++-12 --version
Ubuntu clang version 12.0.1-++20210525082622+328a6ec95532-1~exp1~20210525063352.95
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang++-12 main.cpp
cpp_ranges.cpp:1:10: fatal error: 'ranges' file not found
#include <ranges>
^~~~~~~~
1 error generated.
to call clang++12
with --std=c++20
doesn't make a difference.
How could I fix it?
libstdc++
... – Tenebroussizeof(std::string)
. With libstdc++, it gives 32, while with libc++, it is 24. Or, you canldd
your program file. – Cicala