• Advertisement
Sign in to follow this  

which find_if predicate?

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, In my program a have a std::vector containing pointers to objects representing riders on a track:
std::vector<Rider *> riders;
Each rider has a position on a racing track. The vector is sorted according to the positions of the riders. Now I would like to group the riders. Two riders belong to the same group if the distance between them is smaller than a certain fixed threshold. I'm trying to find the group boundaries using the standard library. My first attempt is the following:
vector<Rider *>::iterator r_it = riders.begin();
vector<Rider *>::iterator r_it2 = riders.begin();

while (r_it2 != riders.end())
{
   r_it2 = find_if(r_it, riders.end(), ?);
   // we have found a group from r_it up to but not including r_it2
   // do something with the group
   r_it = r_it2;
}
At the position of the question mark I would like to have some function that returns true if a rider is the beginning of a new group. Is such a function possible? Or shouldn't I use find_if?

Share this post


Link to post
Share on other sites
Advertisement
You'll probably be more interested in the adjacent_find algorithm.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement