Search code examples
c++macrosboost-preprocessor

How do I expand all except for the first parameter to a variadic macro?


I want to have a macro MAC(...) which expands to all except the first argument passed to it. How do I achieve this?

My first thoughts were to convert the __VA_ARGS__ to a BOOST_PP_TUPLE and then do a POP_FRONT operation:

#define MAC(...)\
  BOOST_PP_TUPLE_POP_FRONT(BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__))
MAC(1,2,3)

But this simply expands to

BOOST_PP_TUPLE_POP_FRONT((1,2,3))

I tried adding the BOOST_PP_EXPAND macro:

#define MAC(...)\
  BOOST_PP_EXPAND(\
    BOOST_PP_TUPLE_POP_FRONT BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__))
MAC(1,2,3)

But I get the same result. What I want is an output of

2, 3

How do I achieve this?

Using templates is not an option nor is using other libraries or tools (other than boost).


Solution

  • Have you tried the simple answer?

    #define Y(ignore, ...) __VA_ARGS__
    #define X(...) Y(__VA_ARGS__)