Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-07-04 11:05:26


Vesa,
        Does this mean that BOOST_PREPROCESSOR_EQUAL will also make an appearance?
To full MACROize Boost.Function I need something like:

#define ADAPTABLE_UNARY() typedef T0 argument_type;
#define ADAPTABLE_BINARY() typedef T0 first_argument_type; \
                           typedef T1 second_argument_type;
#define
// Later...
BOOST_PREPROCESSOR_IF(BOOST_PREPROCESSOR_EQUAL(1,n),
                      ADAPTABLE_UNARY,
                      BOOST_PREPROCESSOR_EMPTY)
BOOST_PREPROCESSOR_IF(BOOST_PREPROCESSOR_EQUAL(2,n),
                      ADAPTABLE_BINARY,
                      BOOST_PREPROCESSOR_EMPTY)

        Thanks for all your great work on this library.
        Doug

On Saturday 30 June 2001 03:46, you wrote:
> 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