1

Say I have an object with key fields a and b. I order them in order of a; should a be equal, then compare b.

I have a set of pointers to such objects. I make a compare function that compares a and if necessary b. I can insert and delete a pointer to an object.

How do I do a find, though, given values of a and b?

Swiss Frank
  • 1,985
  • 15
  • 33
  • What is the C++ version you are using (this is directly supported in C++14 and later, with just a little bit of glue and duct tape)? Also, do you mean that your set uses a comparator class that compares pointers to your objects by dereferencing them, and comparing the pointed-to objects' `a` and `b`? – Sam Varshavchik Jan 24 '21 at 16:06
  • C++11, and yes. – Swiss Frank Jan 24 '21 at 16:16
  • 2
    Unfortunately there is no easy solution for C++11, only C++14 and later. In C++11 you'll have to create a dummy object with the values of `a` and `b`, and `find()` a pointer to it. – Sam Varshavchik Jan 24 '21 at 16:19
  • ...while there is so-called [transparent compare](https://stackoverflow.com/q/20317413/7478597) since C++14. – Scheff's Cat Jan 24 '21 at 18:46

0 Answers0