23 Nov
2011
23 Nov
'11
4:26 p.m.
It is very difficult to realize?
#include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/random_access_index.hpp> using namespace boost::multi_index; struct item { item(int i) : i_(i) {} int i_; }; typedef multi_index_container< item, indexed_by< random_access<>, ordered_non_unique<member<item, int, &item::i_> > >
container;
int main() { container c; c.insert(c.end(), item(2)); c.insert(c.end(), item(1)); c.insert(c.end(), item(3)); c.insert(c.end(), item(4)); for (container::const_iterator i = c.begin(); i != c.end(); ++i) std::cout << i->i_ << std::endl; }