template函数获得2个迭代器,开始和结束迭代器。
模板数据类型iterType
是迭代器类型。尝试将当前迭代器值等于lambda函数中的最大值时出现错误:
[&](iterType* current) {if (current > 0) current = max; }
template<typename iterType>
void modify_each(iterType beg,iterType end) //3.3 #17
{
typename iterType::value_type max = *beg;
for (auto it = beg; it != end; it++)
{
if (max < *it) max = *it;
}
std::for_each(beg,end,[&](iterType* current) {if (current > 0) current = max; });
}