$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2004-03-04 20:51:45
> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Jonathan Turkanis
> > When you pass EMPTY() as an argument to IF, it expands to nothing
> before the
> > replacement list is rescanned, yielding:
>
> Somehow I thought EMPTY() would be lazier. I guess it can't
> be that smart -- it wouldn't know how lazy to be.
You'd be surprised. :) Chaos can do things very similar to this.
#include <chaos/preprocessor/punctuation/comma.h>
#include <chaos/preprocessor/recursion/expr.h>
#include <chaos/preprocessor/recursion/rail.h>
#define RCOMMA() CHAOS_PP_RAIL(CHAOS_PP_COMMA)()
#define A(x) B(x)
#define B(x) C(x)
#define C(x) D(x)
#define D(x) x
A(CHAOS_PP_COMMA()) // error
CHAOS_PP_EXPR(CHAOS_PP_WALL( A(RCOMMA()) ) // ,
Further, Chaos can count the number of scans that the argument x undergoes, and
then delay an invocation until just before the last scan:
#include <chaos/preprocessor/arithmetic/dec.h>
#include <chaos/preprocessor/recursion/delay.h>
#include <chaos/preprocessor/recursion/delve.h>
#define AF CHAOS_PP_HALT( A(CHAOS_PP_DELVE()) )
A( CHAOS_PP_DELAY(CHAOS_PP_DEC(AF), CHAOS_PP_COMMA)() ) // ,
Of course, this is all irrelevant in this case anyway because IF is already lazy
in Chaos:
#include <chaos/preprocessor/facilities/empty.h>
#include <chaos/preprocessor/control/if.h>
#define PARAM(has_param) \
CHAOS_PP_IF(has_param)( \
typename Param, CHAOS_PP_EMPTY() \
) \
/**/
> > #define PARAM(has_param) \
> > BOOST_PP_IF( \
> > BOOST_PP_IDENTITY(typename Param), \
> > BOOST_PP_EMPTY \
> > )() \
> > /**/
> >
> > // or:
> > // #define PARAM(has_param) \
> > // BOOST_PP_EXPR_IF(has_param, typename Param) \
> > // /**/
>
> I like the first better because it's self-contained.
I prefer the second in most cases because it requires the use of less
primitives.
> Thanks for your patience with my preprocessor naïveté.
No problem at all.
Regards,
Paul Mensonides