[multi-index]/shared_ptr template issue - compiles on MSVC8 but not gcc
Hi,
I'm using boost versions 1.33.1 and 1.34.1 with gcc 4.1.2 (Linux)
and boost 1.33.1 with gcc 3.3.2 on solaris and MSVC8
I'm trying to use multi_index as a container indexed by two integers
in a class called MapEntry. The two indices represent a unique key
number "key" and a possibly non-unique timestamp "age". To make it
generic I have the data in a shared_ptr<T> in the MapEntry class
because I wanted to use the aged map functionality with many classes
in the shared_ptr:
// the tags
struct keytag { };
struct agetag { };
template <typename T>
struct MapEntry
{
.... stripped out all constructors and methods ...
int key;
int age;
private:
boost::shared_ptr<T> payload;
};
and the multi_index_container setup as a wrapper class since C++ doesn't have typedef templates
because I figured I needed that to get the "T" into the MapEntry<T> ....
template<typename T>
class AgedMap {
typedef T map_type;
public:
typedef multi_index_container<
MapEntry<T>,
indexed_by<
ordered_unique<
tag<keytag>, BOOST_MULTI_INDEX_MEMBER(MapEntry<T>, int, key) >,
ordered_non_unique<
tag<agetag>, BOOST_MULTI_INDEX_MEMBER(MapEntry<T>, int, age) >
>
> AGEDMAPTYPE;
};
and in main() I declare the container as:
AgedMap
Mark Schlegel:
// this hard coded one compiles and runs on all my platforms // but loses the whole point of genericness //typedef AgedMap
::AGEDMAPTYPE::index<agetag>::type AGE_INDEX; // this AGE_INDEX does not on gcc but DOES compile on MSVC8 typedef AgedMap<T>::AGEDMAPTYPE::index<agetag>::type AGE_INDEX;
Try adding 'typename' after 'typedef'.
Hello Mark,
----- Mensaje original -----
De: Mark Schlegel
// this AGE_INDEX does not on gcc but DOES compile on MSVC8 typedef AgedMap<T>::AGEDMAPTYPE::index<agetag>::type AGE_INDEX;
The correct syntax is typedef typename AgedMap<T>::AGEDMAPTYPE::template index<agetag>::type AGE_INDEX; (note the intervening template keyword) which, just for succintness, in your particular ought to be the same, I think, as typedef typename MIContainer::template index<agetag>::type AGE_INDEX; The dependent template keyword can cause problems in non-conformant compilers. If you meet those, try the variants: typedef typename boost::multi_index::index< typename AgedMap<T>::AGEDMAPTYPE,agetag>::type AGE_INDEX; or typedef typename boost::multi_index::index< MIContainer,agetag>::type AGE_INDEX; Good luck, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (3)
-
"JOAQUIN LOPEZ MU?Z"
-
Mark Schlegel
-
Peter Dimov