Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2006-01-20 14:11:15


----- Mensaje original -----
De: Bruno Martínez <br1_at_[hidden]>
Fecha: Viernes, Enero 20, 2006 4:35 pm
Asunto: Re: [boost] [multi_index] intrusive multi_index poll for
interest

> On Fri, 20 Jan 2006 05:52:22 -0200, Joaquín Mª López Muñoz
> <joaquin_at_[hidden]> wrote:
>
> > OK, you have shown a realistic scenario where the feature
> > is valuable, so I'm putting this into my todo list --probably
> > I can have it in time for 1.34, but I'm very slow writing and
> checking> things :) Any suggestions about the name/syntax?
> Something like:
> >
> > iterator iter_to(const value_type& x)const;
>
> iterator_from()?
>
> I don't know. I'm spanish speaking too.

Pues ponemos entonces

dame_el_iterador(const value_type& x);

:)

(sólo bromeaba, saludos desde España)

>
> > Alas, iterator() can't be used as the name of the member
> function, since
> > it is already a nested typedef of indices.
>
> How is this feature implemented? Substracting char*?
>

Nodes are derived from the following class

template<typename Value>
struct pod_value_holder
{
  typename aligned_storage<
    sizeof(Value),
    alignment_of<Value>::value
>::type space;
};

where "space" is used to hold the value (guaranteed
to serve this purpose by TR1).
Given a value_type*, we are allowed to cast it to a
aligned_storage<...>* (TR1) and then to a
pod_value_holder<value_type>* (std 9.2.17). From here
we only need a static_cast to downcast to a node_type*
(nodes are derived from pod_value_holder). And indices
only need such node_type* to make an iterator.

Briefly put, nodes store the value field in their
first position, and a careful leverage of
aligned_storage<>, POD guarantees and downcasting allows
us to *portably* convert a pointer to the value to a
pointer to the whole node.

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