[Boost.MultiIndex] Parameterizing multi_index_container on a template parameter

Hello,
I am having problems using a multi_index_container in the context of a
template class, and I am hoping someone here can help me. This is a
condensed example:
template<class T> struct C {
typedef multi_index_container<T> SomeSet;
SomeSet container;
// I learned I need typename, since this is an implicit type
typedef typename multi_index_container<T>::nth_index<0>::type
SomeSetIndex;
void f()
{
SomeSetIndex& index = container.get<0>();
}
};
The typedef for SomeSetIndex did not compile. g++-4.2 reported (I
stripped something from the message that I think is not relevant):
error: non-template 'nth_index' used as template
note: use 'multi_index_container

Hi Julius, ________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de Julius Ziegler [ziegler@mrt.uka.de] Enviado el: viernes, 04 de julio de 2008 18:16 Para: boost-users@lists.boost.org Asunto: [Boost-users] [Boost.MultiIndex] Parameterizing multi_index_container on a template parameter
Hello,
I am having problems using a multi_index_container in the context of a template class, and I am hoping someone here can help me. This is a condensed example:
template<class T> struct C { typedef multi_index_container<T> SomeSet; SomeSet container;
// I learned I need typename, since this is an implicit type typedef typename multi_index_container<T>::nth_index<0>::type SomeSetIndex;
void f() { SomeSetIndex& index = container.get<0>(); } }; [...]
Template syntax in so-called dependent contexts is certainly a pain in the aisle. Just as you had to use "typename" in the definition of SomeSetIndex because it's in dependent context, so must you also add "template" both in the definition of SomeSetIndex and in the use of get<> to help the compiler deal with the subsequent <...> chunk: typedef typename multi_index_container<T>:: template nth_index<0>::type SomeSetIndex; void f() { SomeSetIndex& index = container.template get<0>(); } An explanation on the usage of disambiguating "template" in dependent contexts is given at: http://www.comeaucomputing.com/techtalk/templates/#templateprefix Hope this helps. Good luck with your project, thanks for using Boost.MultiIndex, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

That helped a lot, thank you very kindly! -Julius
participants (3)
-
JOAQUIN M. LOPEZ MUÑOZ
-
Julius
-
Julius Ziegler