#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
}
static_assert
错误信息:
要使用 view::for_each,函数 F 必须返回 InputRange 概念的模型。
std::for_each
接受一个返回的函子void
,为什么ranges::view::for_each
要求函子必须返回一个模型InputRange
?