I am learning about ranges and as I learned about range adaptors, they only accept viewable_range as the first argument according to cppreference RangeAdaptorObject.
But when I tested this code on Compiler Explorer:
auto val = std::views::drop(std::vector{1, 2, 3, 4, 5}, 2);
I found that for clang 16.0.0 and gcc 12.0 (both with -std=c++20), this code does compile, while for any older version it does not.
I also tried:
auto val = std::views::transform(std::vector{1, 2, 3, 4, 5}, 2);
This does not compile for any versions of compilers.
So why is it allowed to passing non-viewable_range to some range adaptors in newer version of compiler?
update:
Thanks for @康桓瑋 to point out my typo, views::transform does compile with rvalue movable range:
auto val = std::views::transform(std::vector{1, 2, 3, 4, 5}, [](int i) { return i; });
std::vector<int>is a viewable range. stackoverflow.com/questions/73537755/…std::views::transformhas stricter requirements, it requires the first argument to be a view object, so that is why it does not work forstd::views::transformviews::transformtakes a callable as a second parameter instead of the integer. So this is just a typo.