This question already has an answer here:
I have tried searching for this but couldn't really find a proper answer. I have a stl::set of a custom class I made.
The class looks like
class myObject{
public:
int a;
int b;
int c;
// constructor and operator < ()
}
The < comparison is based on b
and c
but I want to find elements in the set by a
. Is there a way to do that other than performing a linear search by iterating over the set and checking for myObject.a
? I am trying to get a sorted container of myObject
but I need to be able to find elements in that container by the identifier a
which is not really involved in the < comparison.
You can do it using boost::multi_index_container
...