Using multi-index as container type in templated class
Hello, I am having trouble using a boost::multi_index_container type in a template class where the multi-index value type is depending on the template arg type of the class. In particular, I'm getting compiler errors when trying to define the iterator and index types using the "type" typedefs in the multi_index container. Apparently, at compile time the index and iterator types cannot be deduced resulting in errors like "cannot convert to typename, etc.". I'm using GCC 3.3.1 and Boost 1.34.1. Following code demonstrates the problem: // std includes #include <iostream> // 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<typename T> class MultiIndex { public: typedef T value_type; typedef mpl::vector< ordered_non_unique<identity<value_type> >, sequenced<> > index_list_t; // multi-index typedef typedef multi_index_container< value_type, index_list_t > mi; // typedefs for index types typedef typename mi::nth_index<0>::type mi_by_value; typedef typename mi::nth_index<1>::type mi_as_seq; // typedefs for index iterators typedef typename mi::nth_index_iterator<0>::type mi_it; typedef typename mi::nth_index_iterator<1>::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.get<1>().begin(), m_c.get<1>().end(), ostream_iterator<int>(cout, " ")); cout << endl; // access by value cout << "\nAccessing ordered:" << endl; copy(m_c.get<0>().begin(), m_c.get<0>().end(), ostream_iterator<int>(cout, " ")); cout << endl; } private: mi m_c; }; int main(int argc, char** argv) { MultiIndex<int> mi; mi.exec(); } It's probably obvious what is wrong with this code but I just don't see it. I tried a non-templated version and that compiles (and works) fine. Thanks, Paul
participants (1)
-
Paul.VanHagen@shell.com