|
Boost Users : |
Subject: [Boost-users] [multi_index] sorted iteration of values
From: Mathieu Champlon (m.champlon_at_[hidden])
Date: 2013-09-04 01:15:53
Hello,
I'm trying to use Boost.MultiIndex to store my data. The idea is to have
a kind of bidirectional multimap (I initially started with Boost.BiMap)
which could model :
std::multimap< SomeType*, std::set< int > > left;
std::multimap< int, SomeType*> right;
I'll need to :
. insert obviously
. remove all ints based on a SomeType*
. remove one given (SomeType*,int)
. for a given int iterate on all SomeType*
. for a given SomeType* iterate in order on all ints
What I have so far is :
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.
Is there a way to achieve this without manually sorting the iterated
values ?
Thank you !
MAT.
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