简体   繁体   中英

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 ).

Have you tried the simple answer?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM