#include <vector>
#include <algorithm>
#include <range/v3/all.hpp>
using namespace ranges;
int main()
{
auto coll = std::vector{ 1, 2, 3 };
std::for_each(coll.begin(), coll.end(), [](auto){}); // ok
coll | view::for_each([](auto){}); // static_assert failure
}
The static_assert
error message:
To use view::for_each, the function F must return a model of the InputRange concept.
std::for_each
takes a functor which returns void
, why does ranges::view::for_each
require the functor must return a model of the InputRange
concept?