accessing a pair<> element of multi_index container, uniquely ordered

I have the following problem using a multi index container which is uniquely ordered on a pair <int,int>. Each time i want to find every pair i that contains a specific integer. The other value of the pair is irrelevant. An example: <0,1> <0,2> <0,3> <1,2> <1,3> <2,3> and I want to find all the pairs with the value 0 as the first integer. function find() wants the whole pair and iterator find(const CompatibleKey& x,const CompatibleCompare& comp)const; doesn't help ,too. * **Here is the declaration of my container** typedef pair<int, int> clusterset; struct cluster { clusterset pair; float distance; cluster(clusterset pair, float distance) : pair(pair), distance(distance) {} }; struct cluster_pair{}; struct cluster_distance{}; typedef multi_index_container< cluster, indexed_by< ordered_unique< tag<cluster_pair>, BOOST_MULTI_INDEX_MEMBER(cluster, clusterset, pair)>, ordered_non_unique< tag<cluster_distance>, BOOST_MULTI_INDEX_MEMBER(cluster, float, distance)> >
cluster_index;*
Any ideas?

I have the following problem using a multi index container which is uniquely ordered on a pair <int,int>. Each time i want to find every pair i that contains a specific integer. The other value of the pair is irrelevant.
An example: <0,1> <0,2> <0,3> <1,2> <1,3> <2,3>
and I want to find all the pairs with the value 0 as the first integer.
Make an additional index for the pair::first, then use equal_range() for this index. Or change your existing index to be a composite index with 2 fields (pair::first, pair::second), then you'll be able to use equal_range() specifying the value of pair::first only. http://www.boost.org/doc/libs/1_42_0/libs/multi_index/doc/tutorial/key_extra...
participants (2)
-
Andrew Kokkalis
-
Igor R