Boost logo

Boost Users :

From: JOAQUIN M. LOPEZ MUÑOZ (joaquin_at_[hidden])
Date: 2008-07-04 13:38:58


Hi Julius,

________________________________________
De: boost-users-bounces_at_[hidden] [boost-users-bounces_at_[hidden]] En nombre de Julius Ziegler [ziegler_at_[hidden]]
Enviado el: viernes, 04 de julio de 2008 18:16
Para: boost-users_at_[hidden]
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


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