Boost logo

Boost :

From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2007-09-24 15:01:44


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk