Boost logo

Boost Users :

Subject: Re: [Boost-users] boost/preprocessor checking if argument is a constant
From: Edward Diener (eldiener_at_[hidden])
Date: 2010-10-08 20:43:42


On 10/8/2010 12:04 PM, Z S wrote:
> All the BOOST_PP functions only work on integer constants.

This is false. Plenty of Boost PP functionality works with any
preprocessor tokens, not just integer preprocessing tokens.

> I want to
> write macros, where the same interface can be used for both constants
> and variables, and only call the BOOST_PP if the argument is a constant,
> and use runtime code if it is a variable. For example,
>
> |#define TWICE(n) BOOST_PP_IF( _IS_CONSTANT(n), \
>
> BOOST_PP_MUL(n,2), \
>
> ( (n)* 2) )

Do you mean by 'constant' a preprocessing token which is an integer ? If
so, I think you are foolish to worry about whether BOOST_PP_MUL(n,2) or
n * 2 is different since you are just generating some constant
expression in either case, and at the very best you might be saving some
incredibly small amount of compilation time one way or another.


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