Boost logo

Boost Users :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2007-02-21 16:17:28


----- Mensaje original -----
De: Boris <boriss_at_[hidden]>
Fecha: Miércoles, Febrero 21, 2007 8:29 pm
Asunto: Re: [Boost-users] [multi_index] function to force to
recreate indexes?
Para: boost-users_at_[hidden]

> On Wed, 21 Feb 2007 20:37:42 +0200, Joaquín Mª López Muñoz
> <joaquin_at_[hidden]> wrote:
>
> > [...]I'm almost regretting having posted this trick :) since all
> > of this is really completely unguaranteed behavior --so if you
> > can do things in a safer fashion please go that way.
>
> I won't use the trick but the code you posted before. :) But your
> proposal with the null_modifier looks like it can be implemented
> in a refresh() method of the multi_index_container and thus used
> by everyone to recreate indexes reliably?

Even the null_modifier thing is not guaranteed behavior; but even
overlooking that fact, you can't use it to implement refresh().
I guess you have something like the following in mind:

  void refresh()
  {
    for(iterator it=begin();it!=end();++it){
      modify(it,null_modifier());
    }
  }

right? This has two problems, the latter of a fundamental
nature:

1. Since elements are repositioned as you traverse them,
you can skip elements, visit repositioned elements twice,
etc.

2. modify() is not guaranteed to work in this context, as
all the elements are shuffled, and modify() assumes that
the only displaced element (at most) is the one being
directly dealt with. This is not a theoretical
limitation, if you try to do it chances are that the
program crashes.

At the end of the day, the problem is not whether we
can have a reliable implementation of refresh(): you
enter into the realm of undefined behavior once you
modify an element externally to the container. By the
time you are to call refresh(), you have already
performed an illegal action.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net