Boost logo

Boost :

From: Vesa Karvonen (vesa.karvonen_at_[hidden])
Date: 2001-07-04 16:57:34


From: "Douglas Gregor" <gregod_at_[hidden]>
> Vesa,
> Does this mean that BOOST_PREPROCESSOR_EQUAL will also make an appearance?

It seems likely. I have implemented a full range of logical operators (all of
the operations below work on non negative integers (non negative decimal
integer literals to be more accurate)):

Boolean:
  BOOL(X) -- convert (non negative) integer to bool (0 or 1)
  NOR(X,Y) -- used for implement the other boolean operations
  NOT(X)
  AND(X,Y)
  OR(X,Y)
  XOR(X,Y)

Eq:
  EQUAL(X,Y)
  NOT_EQUAL(X,Y)

Ord:
  LESS(X,Y)
  LESS_EQUAL(X,Y)
  GREATER(X,Y)
  GREATER_EQUAL(X,Y)

However, I'm currently not entirely satisfied with the technique I used. I
hope to be able to implement all of the above and arithmetic operations
(ADD,SUB,MUL,DIV,MOD,...) using a single WHILE primitive (i.e. I don't want to
have 2ND_WHILE, 3RD_WHILE, etc...).

> 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

Thanks for having a problem that needs the EQUAL primitive! You have just
significantly increased my motivation for continuing work on the library.

...

The C preprocessor is basically a functional language which has some severe
limitations. It is possible to simulate many functional programming idioms
using the C preprocessor. For instance, it is possible to simulate recursion,
tuples, lists, and even higher order functions, but each of these have severe
limitations.

You can do many fun things with the preprocessor. For example:

  BOOST_PREPROCESSOR_REPEAT(30,PRIME,A,B)

turns into:

  2 3 - 5 - 7 - - - 11 - 13 - - - 17 - 19 - - - 23 - - - - - 29 - 31

and the following snippet

  #define TEST_STR (H,(O,(T,(S,(T,(U,(F,(F,(__,__)))))))))

  TOKENIZE(TEST_STR)
  TOKENIZE(REV(MAP(TO_LOWER,TEST_STR)))

turns into:

  HOTSTUFF
  ffutstoh

Where TOKENIZE is implemented using the following code:

  #define TOKENIZE(L) FOLDR1(BOOST_PREPROCESSOR_CAT,L)


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