question about boost::multi_index_container

I used to use map to access elements. map has a good feature that it sort the element automatically. Now I need a map which can access element through multiple key values. So I choosed boost::multi_index_container. I defined a container as follows.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
struct elem {
	int a,b;
	elem(int aa,int bb):a(aa),b(bb) {}
};

typedef multi_index_container <
	elem,
	indexed_by<
		ordered_non_unique<
			composite_key<
				elem,
				member<elem,int,&elem::a>,
				member<elem,int,&elem::b>
			>
		>
	>
> test;

What I am wondering is whether boost::multi_index_container can sort elements automatically. Specifically, are all elements extracted through iterator from begin to end shown below having b values between 2 and 100?
1
2
3
test t;
test::iterator begin = t.lower_bound(make_tuple(1,2));
test::iterator end = t.upper_bound(make_tuple(1,100));

Thanks for helping me out beforehand.
Last edited on
Ordered indices (ordered_unique and ordered_non_unique) maintain sorted sequences
http://www.boost.org/doc/libs/1_56_0/libs/multi_index/doc/tutorial/basics.html#ord_indices.
thanks for reply. but my question is about the sequence of the composite key. I know that the the elements are sorted according to the values of their keys. But how are the elements with composite key being sorted? Are the elements sorted according to the first key, then the elements with the same value of the first key are sorted according to the second one?
> re the elements sorted according to the first key,
> then the elements with the same value of the first key are sorted according to the second one?

Yes. http://coliru.stacked-crooked.com/a/62f7ba9c15852925
Topic archived. No new replies allowed.