passing comma to preprocessor

C

Christof Warlich

Hi,

I need to use boost's BOOST_PP_IF(condition, then, else) macro, with "condition" being evaluated
from a template, e.g. is_convertible<typename A, typename B>.

Thus, with two classes A and B, I'd like to write:

BOOST_PP_IF(is_convertible<A, B>::value, std::cout << "if\n", std::cout << "else\n");

Unfortunately, the preprocessor complains because it sees 4 parameters instead of 3 due to the comma
between the template parameters.

To make my question independent from boost, having a macro like

#define M(x) x

how do I pass something like

someTemplate<x, y> to M(x)?

Thanks for any ideas,

Christof

P.S.: I already tried boost's BOOST_PP_COMMA() macro, but this did not solve the problem.
 
M

Micah Cowan

Christof Warlich said:
BOOST_PP_IF(is_convertible<A, B>::value, std::cout << "if\n", std::cout << "else\n");

Try:

BOOST_PP_IF((is_convertible<A, B>::value), std::cout << "if\n", std::cout << "else\n");
 
C

Christof Warlich

Micah said:
Try:

BOOST_PP_IF((is_convertible<A, B>::value), std::cout << "if\n", std::cout << "else\n");
Oh, yeah, thanks, this is it. But anyway, I misinterpreted BOOST_PP_IF
to be a macro wrapper for some template "if" implementation, which it
doesn't seem to be. Instead, it looks like just being some preprocessor
code, so my construct would not have worked even without my comma-problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top