|
Boost : |
From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2004-08-31 09:42:03
Vladimir Prus ha escrito:
> Joaquín Mª López Muñoz wrote:
>
> > > 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);
> > > const_cast<Variable_declaration&>(*existing)
> > > .make_external();
> >
> > 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.
>
> OK. I started to wonder because the method above appears to be much more
> efficient than 'replace' and much more simple that 'modify', so I'm about to
> use it as default.
>
Well, the following
index.modify(
existing,
boost::mem_fn(&Variable_declaration::make_external));
is not much more cumbersome, and it is certainly safer.
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