U
Urs Thuermann
Functions like std::find_if() and std::remove_if() need a predicate
that takes an argument from the range these functions iterate over and
returns a bool. Many tutorials and docs show how one can find, e.g.,
the first odd int or remove all odd ints from a container, using a
predicate "bool isodd(int)".
However, I often need to iterate through a container and compare one
member of each element to some value, like this
User *find_user(string login)
{
for (it = users.begin(); it != users.end(); ++it) {
if (it->login == login)
break;
...
}
Functions like find_if() or remove_if() look elegant in many cases but
are there versions which call predicates taking an additional
argument, e.g. a login name to compare with?
urs
that takes an argument from the range these functions iterate over and
returns a bool. Many tutorials and docs show how one can find, e.g.,
the first odd int or remove all odd ints from a container, using a
predicate "bool isodd(int)".
However, I often need to iterate through a container and compare one
member of each element to some value, like this
User *find_user(string login)
{
for (it = users.begin(); it != users.end(); ++it) {
if (it->login == login)
break;
...
}
Functions like find_if() or remove_if() look elegant in many cases but
are there versions which call predicates taking an additional
argument, e.g. a login name to compare with?
urs