// std includes #include // boost includes #include "boost/multi_index_container.hpp" #include "boost/multi_index/ordered_index.hpp" #include "boost/multi_index/sequenced_index.hpp" using namespace std; using namespace boost; using namespace boost::multi_index; // try also class keyword here template class MultiIndex { public: typedef T value_type; typedef mpl::vector< ordered_non_unique >, sequenced<> > index_list_t; // multi-index typedef typedef multi_index_container< value_type, index_list_t > mi; // typedefs for index types typedef typename nth_index::type mi_by_value; typedef typename nth_index::type mi_as_seq; // typedefs for index iterators typedef typename nth_index_iterator::type mi_it; typedef typename nth_index_iterator::type mi_seq_it; MultiIndex() { // add pair to multi-index container mi_as_seq& seq = get<1>(m_c); seq.push_back(9); seq.push_back(8); seq.push_back(7); seq.push_back(6); seq.push_back(5); seq.push_back(4); seq.push_back(3); seq.push_back(2); seq.push_back(1); seq.push_back(0); } void exec() { // access as sequence cout << "\nAccessing as sequence:" << endl; copy(m_c.template get<1>().begin(), m_c.template get<1>().end(), ostream_iterator(cout, " ")); cout << endl; // access by value cout << "\nAccessing ordered:" << endl; copy(m_c.template get<0>().begin(), m_c.template get<0>().end(), ostream_iterator(cout, " ")); cout << endl; } private: mi m_c; }; int main(int argc, char** argv) { MultiIndex mi; mi.exec(); }