Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-06-30 15:21:43


I am probably being dense. Why would one want this in lieu of
#define ADD(x,y) ((x)+(y))

??

----- Original Message -----
From: "Vesa Karvonen" <vesa.karvonen_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Saturday, June 30, 2001 3:46 PM
Subject: [boost] PREPROCESSOR library review

> Hi,
>
> A few hours ago, I invented a technique for implementing ADD(X,Y) and
SUB(X,Y)
> using linear amount of tokens. In other words, code like this does what
you'd
> expect:
>
> assert(BOOST_PREPROCESSOR_ADD(5,10) == 15);
> assert(BOOST_PREPROCESSOR_SUB(10,5) == 5);
>
> The solution is a repetition primitive that repeatedly calls the specified
> macro with the specified parameter (here without the prefix):
>
> #define REPEAT_CALL(N,M,P) REPEAT_CALL_DELAY(N,M,P)
> #define REPEAT_CALL_DELAY(N,M,P) REPEAT_CALL##N(M,P)
> #define REPEAT_CALL0(M,P)
> #define REPEAT_CALL1(M,P) M(P)
> #define REPEAT_CALL2(M,P) M(M(P))
> #define REPEAT_CALL3(M,P) REPEAT_CALL2(M,M(P))
> #define REPEAT_CALL4(M,P) REPEAT_CALL3(M,M(P))
> #define REPEAT_CALL5(M,P) REPEAT_CALL4(M,M(P))
> // ...
>
> In other words, this evaluates to something like:
>
> M(M(M(M(M(M(P))))))
>
> The ADD and SUB primitives are then implemented like this:
>
> #define BOOST_PREPROCESSOR_ADD(X,Y)\
> BOOST_PREPROCESSOR_REPEAT_CALL(Y,BOOST_PREPROCESSOR_INC,X)
>
> #define BOOST_PREPROCESSOR_SUB(X,Y)\
> BOOST_PREPROCESSOR_REPEAT_CALL(Y,BOOST_PREPROCESSOR_DEC,X)
>
> ...
>
> I have also made some updates, based on review comments, to the library
> documentation.
>
> If you want, I can update the library files, so that you can test and try
the
> new ADD and SUB primitives.
>
> It is highly likely that other interesting and useful operations could be
> implemented in the future.
>
> -Vesa
>
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


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