Boost logo

Boost Users :

From: Peter Bartlett (pete_at_[hidden])
Date: 2008-03-13 13:41:46


Quoting "Warlich, Christof \(Christof\)" <cwarlich_at_[hidden]>:

>> There's a few things wrong with this.
>> Firstly you write BOOST_PP_IIF but include <boost/preprocessor/if.hpp>
>> - you probably meant BOOST_PP_IF.

> Well, <if.hpp> includes <control/if.hpp> which includes
> <control/iif.hpp>,
> and I thought I stay at the top level of the boost/preprocessor
> directory
> as the content of subdirectories may become subject of change.

Oops sorry I'm misread the include. What you're doing is fine.

>>
>> But more seriously your "condition" is not a number known at
>> preprocessor-time - i.e. it won't evaluate to a number at
>> pre-processor time, only at compile-time when the
>> boost::is_convertible template magic kicks in. Thus
>> BOOST_PP_IF wouldn't expand as you expect.
> Hmm, but then, what is the advantage compared to an ordinary #if
> statement? Actually, I thought that BOOST_PPP_IF is a wrapper for
> some template "if", e.g. like
>
> template<bool condition, class Then, class Else> struct IF {typedef Then
> RET;};
> template<class Then, class Else> struct IF<false, Then, Else> {typedef
> Else RET; };
>
> Was this assumption wrong?

I'm afraid so. BOOST_PP_IF is a preprocessor-time "if". I.e. different
code is generated by the preprocessor depending on the value of the
first argument. Most compilers have a switch so that you can use do
the preprocessing part of compilation if you wish.

In your actual case, you'll need to do clas template specicalisation
(no macros) to achieve what you want.


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