2

If I have a boost::multi_index as follows,

typedef multi_index_container<
    employee,
    indexed_by<    
        hashed_unique<mem_fun<employee, std::string, &employee::getname> >,
        hashed_unique<mem_fun<employee, int, &employee::getage> >
    > 
> employee_set;

I understand that the objects of class "employees" that are inserted into this container are stored in such a way that it can be retrieved in O(1) time(as a hash map).

How will it be stored when the member variables(name, age) are updated during the course of the program(like maybe with something like setname or setage) and still be hashed using those values? Am I understanding something wrong?

TIA

-R

codeworks
  • 149
  • 1
  • 15

1 Answers1

1

From the documentation:

The iterators provided by every index are constant, that is, the elements they point to cannot be mutated directly. This follows the interface of std::set for ordered indices but might come as a surprise for other types such as sequenced indices, which are modeled after std::list, where this limitation does not happen. This seemingly odd behavior is imposed by the way multi_index_containers work; if elements were allowed to be mutated indiscriminately, we could introduce inconsistencies in the ordered indices of the multi_index_container without the container being notified about it. Element modification is properly done by means of update operations on any index.

In other words, you only have const access to your stored objects, unless you use the container's updating functions, at which point it can hook into the call and adjust the hashes on-the-fly.

Quentin
  • 62,093
  • 7
  • 131
  • 191