Jump to content
  • Advertisement
Sign in to follow this  
simonloach

comparison function arguments when using std::set

This topic is 3657 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, I've thought of a better way to do what I was doing now but it's annoying me that I can't remember how to specify the comparison function in a std::set which takes more than two arguments. std::set<graphics::light_point, graphics::light_comparison> sortedlights(lights_.begin(), lights_.end()); where light_comparison is declared as: bool light_comparison(const light_point& l1, const light_point& l2, const D3DXVECTOR3& viewerPosition) const; So what should I use in the definition of sortedlights to make it correct?

Share this post


Link to post
Share on other sites
Advertisement
If you want to create a set that stores a data argument to sort the set by, you can use a comparison function object with state as the second template argument. Ex:


struct Comparator {
Comparator(int arg) : data(arg) {}
int data;
bool operator()(const Object & lhs, const Object & rhs) {
return my_comparison(lhs, rhs, data);
}
};

std::set<Object, Comparator> s(Comparator(0));

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!