[serialization] export macros

Hi, working with the post-review version #20 of the serialization library, I encountered problems with respect to the export macros (BOOST_CLASS_EXPORT_GUID etc.). I decided to check the Boost CVS for changes - but it turns out the problems became worse :-( (FWIW, I use gcc 3.4.1 on a Linux x86 machine.) I need to register class template specializations that have several arguments. Unfortunately, the preprocessor does not know about template argument lists and treats the 2nd, 3rd,... template argument as separate macro arguments. Therefore, the expansion of the export macros fails due to a wrong number of macro arguments. It does not help to surround the template-id with parentheses since after the macro expansion the argument is used as a template argument itself and the compiler rejects the "superfluous" parentheses in the new template argument list. With serialization#20 I had the workaround to define a typedef for the template specialization within an anonymous namespace. I could then pass this typedef to the export macros. But this approach becomes soon impractical if you write a library with internal class templates depending on some user defined types. Does anyone know a work around that does not need the typedefs? I had a look at the preprocessor library but I couldnt come up with a solution. Is there an alternative to the macros for registering types? (A sample program exhibiting what I am trying is attached.) Anyway, with the current CVS, even above mentioned workaround fails; I am going to discuss the reason in a separate posting. Christoph -- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html

Christoph Ludwig wrote: [snip]
a look at the preprocessor library but I couldnt come up with a solution. Is there an alternative to the macros for registering types? (A sample program exhibiting what I am trying is attached.) [snip] // Doesn't work (wrong number of macro arguments ): // BOOST_CLASS_EXPORT( DerivedStatus< Algo< int, double > > );
Did you try using BOOST_PP_COMMA ?? For example: BOOST_CLASS_EXPORT( DerivedStatus< Algo< int BOOST_PP_COMMA double > > ); -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Rene Rivera
[snip]
a look at the preprocessor library but I couldnt come up with a solution. Is there an alternative to the macros for registering types? (A sample program exhibiting what I am trying is attached.) [snip] // Doesn't work (wrong number of macro arguments ): // BOOST_CLASS_EXPORT( DerivedStatus< Algo< int, double > > );
Did you try using BOOST_PP_COMMA ?? For example:
BOOST_CLASS_EXPORT( DerivedStatus< Algo< int BOOST_PP_COMMA double > > );
Should be with nullary parentheses: BOOST_CLASS_EXPORT( DerivedStatus< Algo<int BOOST_PP_COMMA() double > > ); Incidently, do we have a function argument mapping for the common case of this type of thing? E.g. template<class> struct pack; template<class T> struct pack<void (T)> { typedef T type; }; BOOST_CLASS_EXPORT( pack<void (DerivedStatus< Algo<int, double > >)>::type ); Or similar? The COMMA() trick will only work through one level of macro expansion. Regards, Paul Mensonides

On Thu, Aug 12, 2004 at 07:03:57PM -0700, Paul Mensonides wrote:
From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Rene Rivera
[snip]
a look at the preprocessor library but I couldnt come up with a solution. Is there an alternative to the macros for registering types? (A sample program exhibiting what I am trying is attached.) [snip] // Doesn't work (wrong number of macro arguments ): // BOOST_CLASS_EXPORT( DerivedStatus< Algo< int, double > > );
Did you try using BOOST_PP_COMMA ?? For example:
BOOST_CLASS_EXPORT( DerivedStatus< Algo< int BOOST_PP_COMMA double > > );
Should be with nullary parentheses:
BOOST_CLASS_EXPORT( DerivedStatus< Algo<int BOOST_PP_COMMA() double > > );
[...]
The COMMA() trick will only work through one level of macro expansion.
Unfortunately, the serialization lib's export macros go through several levels. Therefore, replacing the commas by BOOST_PP_COMMA() does not help. (I tried it a few minutes ago.)
Incidently, do we have a function argument mapping for the common case of this type of thing?
E.g.
template<class> struct pack;
template<class T> struct pack<void (T)> { typedef T type; };
BOOST_CLASS_EXPORT( pack<void (DerivedStatus< Algo<int, double > >)>::type );
That did the trick! Great! I am not sure which of Boost's libraries is the most adequate place for such a tool (preprocessor? mpl?), but it is certainly valuable. And if / once there is such a tool in Boost, then the documentation of macros that are likely to take classes genareted from templates as arguments should refer to it. Regards Christoph -- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html
participants (3)
-
Christoph Ludwig
-
Paul Mensonides
-
Rene Rivera