Here’s a small (ok, maybe not minimal) example
#include <range/v3/view/concat.hpp>
#include <range/v3/view/transform.hpp>
#include <unordered_set>
#include <vector>
#include <iostream>
using namespace ranges::views;
int main() {
constexpr auto removeFrom = [](auto& s){
return [&s](auto k){
s.erase(k);
return 10*k;
};
};
std::vector<int> v{1,2,3,4,5};
std::unordered_set<int> s{7,2,3,8};
auto c = concat(v | transform(removeFrom(s)),
s | transform([](auto x){ return 100*x; }));
std::cout << c << std::endl;
}
Notice that iterating on v | transform(removeFrom(s))
will result in removing elements from s
.
Now, I know that the evaluation order of the two argumensts to concat
is not guaranteed by the standard, but the evaluation of both v | transform(removeFrom(s))
and s | transform([](auto x){ return 100*x; }))
is not really doing any iteration yet. But the body of concat
will iterate on v | transform(removeFrom(s))
first, and then on
s | transform([](auto x){ return 100*x; }))
, so is there any problem?
I’m asking the question in general, so both for the 3 valid point in the product range-v3std-ranges × c++17c++20.
2