multi_index - BOOST_MULTI_INDEX_MEMBER template arg limit of 1?

This is my multi_index code for the type that goes in the container (MapEntry<Keyt, T>)and the container definition "AgedMap" ------------------- struct keytag { }; struct agetag { }; template <typename KEYT, typename T> struct MapEntry { MapEntry(KEYT key_, int age_, T* ptr) : key(key_), age(age_) { payload.reset(ptr); } ~MapEntry() { //cout << "destructing entry for key " << key << endl; } friend std::ostream& operator<<(std::ostream& os, const MapEntry<KEYT,T>& am) { os << "key: " << am.key << " " << " age: " << am.age << " " << std::endl; return os; } friend int getAge(const MapEntry<KEYT,T>& am) { return am.age; } friend KEYT getKey(const MapEntry<KEYT,T>& am) { return am.key; } T* getPayload() const { return payload.get(); } //void setKey(int key_) { key = key_; } void setAge(int age_) { age = age_; } KEYT key; int age; private: boost::shared_ptr<T> payload; }; template<typename KEYT, typename T> class AgedMap { public: typedef multi_index_container< MapEntry<KEYT, T>, indexed_by< ordered_unique< tag<keytag>, BOOST_MULTI_INDEX_MEMBER(MapEntry<KEYT,T>, KEYT, key) >, ordered_non_unique< tag<agetag>, BOOST_MULTI_INDEX_MEMBER(MapEntry<KEYT,T>, int, age) > > > AGEDMAPTYPE; }; -------------------- the above was working when my MapEntry was just MapEntry<T> but then I modified it to have two template args: MapEntry<KEYT, T> so I could has different Key types and have the different classes in the shared_ptr because later I realized I would want both st::string and int to be possible keys. But my multi_index would not compile on gcc 4.1.2 with the MapEntry having two templates and results in error: "error: macro "BOOST_MULTI_INDEX_MEMBER" passed 4 arguments, but takes just 3" so gcc thinks it's parsing out 4 args and not three. I then thought it was the typical macro problem with parsing so I put parens around the MapEntry first arguments to BOOST_MULTI_INDEX_MEMBER(): BOOST_MULTI_INDEX_MEMBER((MapEntry<KEYT,T>), KEYT, key) >, This didn't help either, is it not allowed to exceed one template argument in an argument to BOOST_MULTI_INDEX_MEMBER() so for example MapEntry<T> is ok but MapEntry<KEYT,T> is not? Mark

Mark Schlegel <moschleg <at> verizon.net> writes: [...]
template<typename KEYT, typename T> class AgedMap { public: typedef multi_index_container< MapEntry<KEYT, T>, indexed_by< ordered_unique< tag<keytag>, BOOST_MULTI_INDEX_MEMBER(MapEntry<KEYT,T>, KEYT, key) >, ordered_non_unique< tag<agetag>, BOOST_MULTI_INDEX_MEMBER(MapEntry<KEYT,T>, int, age) > > > AGEDMAPTYPE; }; [...] "error: macro "BOOST_MULTI_INDEX_MEMBER" passed 4 arguments, but takes just 3"
so gcc thinks it's parsing out 4 args and not three.
I then thought it was the typical macro problem with parsing so I put parens around the MapEntry first arguments to BOOST_MULTI_INDEX_MEMBER():
BOOST_MULTI_INDEX_MEMBER((MapEntry<KEYT,T>), KEYT, key) >,
This didn't help either, is it not allowed to exceed one template argument in an argument to BOOST_MULTI_INDEX_MEMBER() so for example MapEntry<T> is ok but MapEntry<KEYT,T> is not?
Hello Mark, The extra parens trick will or won't work depending on the context where the overparenthesized arg is expanded into --in this case you're out of luck. You've got several other options, among them the following: 1. You can use boost::multi_index::member<> directly; after all, BOOST_MULTI_INDEX_MEMBER is mainly provided as a workaround for some broken compilers (though its syntax is terser than using naked member<>): member<MapEntry<KEYT,T>, KET,&MapEntry<KEYT,T>::key> 2. Use a typedef so that the extra comma does not appear inside the macro: typedef MapEntry<KEYT,T> ValueType; ... BOOST_MULTI_INDEX_MEMBER(ValueType, KEYT, key) Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (2)
-
Joaquin M Lopez Munoz
-
Mark Schlegel