Boost logo

Boost Users :

From: Thomas Wenisch (twenisch_at_[hidden])
Date: 2002-09-27 11:01:16


On Fri, 27 Sep 2002 scleary_at_[hidden] wrote:

> > From: zhangwusheng [mailto:yg-boost-users_at_[hidden]]
> >
> > Hi,all,
> > In file suffix.hpp there are lines:
> >
> > #define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
> > #define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
> > #define BOOST_DO_JOIN2( X, Y ) X##Y
> >
> >
> > why donot we define such macro instead:
> > #define BOOST_JOIN( X, Y ) X##Y
>
> The idea behind BOOST_JOIN is to force the preprocessor to scan the macro
> parameters for replacement before merging the results with ##. So, it
> changes the meaning if one of the parameters is a macro:
> #define Z_BOOST_JOIN(X, Y) X##Y
> Z_BOOST_JOIN(id_, __LINE__) // Expands to "id___LINE__"
> BOOST_JOIN(id_, __LINE__) // Expands to "id_13" if __LINE__ is 13
>
> However, I'm not sure why BOOST_DO_JOIN2 is used; it seems to me that only
> one layer of indirection should work. I assume it's to work around some
> compiler's non-conforming preprocessor.
>

I believe that this is some kind of performance optimization for EDG-based
preprocessors. For some reason, "delaying" a macro invocation improves
performance (compile time) dramatically. Doesn't make any sense to me,
but apparently, that's the way it is.

I believe Paul Mensonides is the one who discovered the trick; I remember
seeing him post about it a couple of months ago when he overhauled the
Preprocessor library to add file iteration. He could confirm that this is
true and perhaps give insight as to why.

Regards,
-Tom Wenisch
Computer Architecture Lab
Carnegie Mellon University


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