From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2004-08-30 11:43:30
Vladimir Prus ha escrito:
> I have a question about the 'modify' method of ordered indexes in the
> multi_index library. I have an iterator obtained from an ordered index and
> would like to modify the pointed element. I'm pretty sure that the
> modification won't change the order, won't create collisions and so on.
> The documentation suggests to use either 'replace', or more efficient 'modify'
> method. Why can't I do the following:
> typedef variables_t::nth_index<1>::type index_t;
> index_t& index = variable_declarations.get<1>();
> index_t::iterator existing = index.find(vd);
You can do this as long as you're 100% sure there won't be collisions
or reorderings. This is no different to const_casting away an element in a
std::set: if you know what you're doing, well, it's OK. That said,
using replace or modify keeps you on the safe side.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk