Jump to content
  • Advertisement
Sign in to follow this  

which find_if predicate?

This topic is 4598 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!