Boost logo

Boost Users :

Subject: Re: [Boost-users] [multi_index] sorted iteration of values
From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2013-09-04 02:15:24


El 04/09/2013 7:15, Mathieu Champlon escribió:
> Hello,
>
> [...]
>
> typedef SomeType* First;
> typedef int Second;
>
> struct Value
> {
> First first;
> Second second;
> };
>
> boost::multi_index::multi_index_container<
> Value,
> boost::multi_index::indexed_by<
> boost::multi_index::ordered_unique<
> boost::multi_index::composite_key<
> Value,
> boost::multi_index::member<
> Value, First, &Value::first >,
> boost::multi_index::member<
> Value, Second, &Value::second >
> >
> >,
> boost::multi_index::ordered_non_unique<
> boost::multi_index::member<
> Value, Second, &Value::second >
> >,
> boost::multi_index::ordered_non_unique<
> boost::multi_index::member<
> Value, First, &Value::first >
> >
> >
> > data;
>
> This works, except for the ints iteration based on a given SomeType*
> because I need
> them to be sorted, and they're not, e.g.
>
> auto range = data.get< 2 >().equal_range( someTypePtr );
> for( auto it = range.first; it != range.second; ++it )
> ;
>
> does not iterate in a sorted order.

Use index #0:

     auto range = data.get< 0 >().equal_range( someTypePtr );

In fact, you can get rid of index #2: when using a composite key you
can search by providing only the first m fields of the key, so for
all practical purposes index #2 is redundant with #0.

Joaquín M López Muñoz
Telefónica Digital

________________________________

Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo.
This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at:
http://www.tid.es/ES/PAGINAS/disclaimer.aspx


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