Boost logo

Boost Users :

Subject: [Boost-users] printing data sorted based on a specific key in boost multi-index container
From: Ramesh (rramesh1_at_[hidden])
Date: 2008-10-09 23:55:54


Hi Joaquin,

Supposing I have a container having three unique keys, Is there a way
I can print data sorted by one of they keys?
At the moment I tried a raw dump - it shows fields based on the first
key (which is key1).

Thanks
Ramesh

----
typedef multi_index_container<
  MyMap,
	indexed_by<
		ordered_unique<
			tag <Key1>, BOOST_MULTI_INDEX_MEMBER(MyMap,std::string,Key1)>,
		ordered_non_unique<
	      		tag<Key2>,BOOST_MULTI_INDEX_MEMBER(MyMap,unsigned long,Key2)>,	
	      	ordered_unique<
	      		tag<Key3>,BOOST_MULTI_INDEX_MEMBER(MyMap,unsigned long,Key3)>
	>
> tMyMap;
class MyContainer {
	
	private:
		tMyMap		MapObj;
	public:
		Show(){
			for (MyMap::iterator it = MyContainer.begin(), itend =
MyContainer.end(); it != itend;++it) {
				cout << it->Key1;
				cout << it->Key2;
				cout << it->Key3;
			}
		}
};
main() {
MyContainer M;
// Assuming I have data inserted in the container like
// ("Id 4", 10, 10)
// ("Id 1", 10, 40)
// ("Id 5", 30, 60)
M.Show()
// The result is as below:
//("Id 5", 30, 60)
// ("Id 1", 10, 40)
// ("Id 4", 10, 10)
}

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