2

I have the following macro:

#define REFLECTABLE(...) \
REFLECTABLE_CONST(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__)==0, __VA_ARGS__)

I ran the pre-processor. It passes to REFLECTABLE_CONST 3==0 instead of 0 or false. In REFLECTABLE_CONST, I am using that value to simulate a conditional as described in this post. So, I need the pre-processor to pass a value. Is there a way to make pre-processor substitute things like 3==0 by false or 0?

Community
  • 1
  • 1
AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68

2 Answers2

2

I couldn't reproduce BOOST_PP_VARIADIC_SIZE being able to have a result of 0, but if you can, this should work:

#define IS_EMPTY_IMPL0 1
#define IS_EMPTY_IMPL1 0
#define IS_EMPTY_IMPL2 0
#define IS_EMPTY_IMPL3 0
#define IS_EMPTY_IMPL4 0
#define IS_EMPTY_IMPL5 0
#define IS_EMPTY_IMPL6 0
#define IS_EMPTY_IMPL7 0
#define IS_EMPTY_IMPL8 0
#define IS_EMPTY_IMPL9 0

#define IS_EMPTY(...) BOOST_PP_CAT(IS_EMPTY_IMPL, BOOST_PP_VARIADIC_SIZE(__VA_ARGS__))

#define REFLECTABLE(...) \
REFLECTABLE_CONST(IS_EMPTY(__VA_ARGS__), __VA_ARGS__)
Simple
  • 13,992
  • 2
  • 47
  • 47
  • **For a future visitor:** I accepted this reply, because it handles the question as is. However, see my own answer, which provides a simpler solution to the actual problem. – AlwaysLearning Dec 11 '15 at 10:10
2

Stumbled upon this solution. Just use this instead:

#define REFLECTABLE(...) \
REFLECTABLE_CONST(BOOST_PP_IS_EMPTY(__VA_ARGS__), __VA_ARGS__)
AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68