I come from the Java world and am not very versed in C ++, so the following question arose. I see that OutputIterator used quite widely. So far, I have seen people use insert like std::back_inserter .
Is it not possible to somehow provide a lambda that is called for each element, instead of writing the elements in the container?
Example:
Instead
std::vector<int> my_vector; set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), std::back_inserter(my_vector));
sort of
set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), to_iterator([](int x) { std::cout << x; }));
source share