[preprocessor] Comparing strings in BOOST_PP_NOT_EQUAL
Hi! I'm developing with preprocessor a class generator, that generates the wrapper classes needed by boost.python when you want to derive in python from polymorph c++-base classes. I would need a Macro that expands to "return" if its argument is not void. I tried the following, but that obiously does not work: #define Return(type) \ BOOST_PP_EXPR_IF(BOOST_PP_NOT_EQUAL(type, void), return) I made a workaround by adding an integer value to my Array that defines the methods signature. But that is redundant. Is there a way to achieve the behaviour above?
AMDG Maximilian Matthe wrote:
Hi!
I'm developing with preprocessor a class generator, that generates the wrapper classes needed by boost.python when you want to derive in python from polymorph c++-base classes.
I would need a Macro that expands to "return" if its argument is not void. I tried the following, but that obiously does not work:
#define Return(type) \ BOOST_PP_EXPR_IF(BOOST_PP_NOT_EQUAL(type, void), return)
I made a workaround by adding an integer value to my Array that defines the methods signature. But that is redundant.
Is there a way to achieve the behaviour above?
It's possible (See BOOST_MPL_PP_TOKEN_EQUAL) but it's probably easier to use void returns: void f(); void g() { return f(); } In Christ, Steven Watanabe
Steven Watanabe schrieb:
AMDG
Maximilian Matthe wrote:
Hi!
I'm developing with preprocessor a class generator, that generates the wrapper classes needed by boost.python when you want to derive in python from polymorph c++-base classes.
I would need a Macro that expands to "return" if its argument is not void. I tried the following, but that obiously does not work:
#define Return(type) \ BOOST_PP_EXPR_IF(BOOST_PP_NOT_EQUAL(type, void), return)
I made a workaround by adding an integer value to my Array that defines the methods signature. But that is redundant.
Is there a way to achieve the behaviour above?
It's possible (See BOOST_MPL_PP_TOKEN_EQUAL) but it's probably easier to use void returns:
void f();
void g() { return f(); }
In Christ, Steven Watanabe
Thanks for your advice. I'm going to use BOOST_MPL_PP_TOKEN_EQUAL. Using void returns would result in writing two functions for each function I want to wrap, so using this macro seems to be a better solution.
participants (2)
-
Maximilian Matthe
-
Steven Watanabe