Boost logo

Boost Users :

Subject: [Boost-users] multi-index container random access index ordered
From: Vladimir Voronkov (voronkovv_at_[hidden])
Date: 2009-11-20 10:18:24


Hi,

 

I defined a container like this:

 

typedef boost::multi_index_container<

      std::pair<int, int>,

      boost::multi_index::indexed_by<

            boost::multi_index::random_access<>,

            boost::multi_index::ordered_unique<

                  boost::multi_index::member<std::pair<int, int>, int, &std::pair<int, int>::first>

> > >

IdContainer;

 

typedef IdContainer::nth_index<0>::type IdsArr;

typedef IdContainer::nth_index<1>::type IdsSet;

 

and then I insert a data into it:

 

      a_set.insert(std::make_pair(1, 0));

      a_set.insert(std::make_pair(3, 0));

      a_set.insert(std::make_pair(2, 0));

      a_set.insert(std::make_pair(5, 0));

      a_set.insert(std::make_pair(4, 0));

 

in this case elements will be “pushed back” in terms of random access index, i. e.

 

      for (size_t i = 0; i < a_arr.size(); i++)

      {

            std::cout << a_arr[i].first << std::endl;

      }

 

will return

 

1

3

2

5

4

 

I would like to have them inserted ordered way, and as long as we have ordered index I suppose it’s possible. How can I do that?

 

I suspect I could do like this:

      a_arr.insert(a_set.find(1), std::make_pair(1, 0));

but it errors about incompatible types of iterators for what a_set.find returns and what a_arr.insert accepts.

 

Or… may be there are some kind of definition of random access index with respect to another index which is ordered??? I don’t know.

 

Your help is appreciated.

 



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