Boost logo

Boost Users :

Subject: Re: [Boost-users] PP: 2 to the power x macro
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2010-02-04 04:26:58


2010/2/4 Ravi <lists_ravi_at_[hidden]>

> On Tuesday 02 February 2010 21:29:40 Hicham Mouline wrote:
> > I can't find this left shift operator in Boost.PP.
> > Do you mean << ?
> > But then how do I evaluate it in the context of the preprocessor?
>
> Unless I have misunderstood your question (very likely), isn't this what
> you
> need?
>
> #define POWER2(a) (1<<a)
> // Example usage in the context of the preprocessor
> #if POWER2(3) == 8
> #error "Success, correct calculation"
> #else
> #error "Failure"
> #endif

How about this?

// Must expand to "int foo8;", but it does not.
int BOOST_PP_CAT(foo, POWER2(3));

Roman Perepelitsa.



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