I need to store some objects in a std:set (or any other kind of lookup table) and search those by name.
For example, suppose I have a class like (pseudo code):
class Person
{
std::string mName;
int mAge;
... //etc
};
I would like to store this on a container and search for objects by name. I cannot insert those on a std::set, because as far I know, I must construct an entire object for searching.
My second though was to use a std::map like std::map, but, I will need to duplicate the name for this and I do not want to duplicate the key.
Is there a way to store this kind of object in a std::set (or any other container) and search by a key (not the object) ?
Thank you