I have a class like this:
struct Thing
{
unsigned index;
};
I use std::map<Thing>to contain my Things. The call code looks something like this:
Thing myThing();
std::map<Thing> things;
things[myThing.index] = myThing;
Thing &thing3 = things[3];
I was wondering if there is an approach that I could use Thing::indexdirectly, without having to implicitly copy it to pair::first.
I think I would need to provide some kind of comparison operator Thing, but that's OK. std::setmay work, but I need the whole object Thingas a key:
std::set<Thing> things;
Thing &thing3 = *things.find(Thing(3));
Besides refactoring Thingin std::pair, can I do better with STL?
source
share