The current implementation of append_name_if uses an undefined variable filter.
Maybe we could replace the example by something like that:
<typename FilterFunction>
auto append_name_if(FilterFunction filter) {
return [filter](std::vector<std::string> previously_collected, const person_t &person) {
if (filter(person))
previously_collected.push_back(name(person));
return previously_collected;
};
}
// ...
template <typename FilterFunction, typename Iterator>
std::vector<std::string> names_for(
Iterator people_begin,
Iterator people_end,
FilterFunction filter)
{
return std::accumulate(
people.cbegin(),
people.cend(),
std::vector<std::string>{},
append_name_if(filter));
}
|