I want a container which can be indexed by a member field and whose other member fields can be modified. I have tried set and found that the element retrieved from the container is readonly version of the element.
for example
1 2 3
set<some_class> s;
//...
set<some_class>::iterator it = s.find(obj);
the element desinated by iterator it is rea donly.
Is there one in STL or boost. Thanks for any recommendation;
It's not read-only, you're probably modifying a copy of the content.
You may want to try a map, it's a dictionary implmentation with an index of your choosing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
e.g.
struct User
{
int uid;
int gid;
std::string name;
std::string shell;
};
typedef std::map<int, User> Users; // map uid to User
Users users;
//...
// change the name of uid 7;
Users::iterator p = users.find(7);
if (p != users.end)
p->name = "Seven";