0

I was wondering if there was a clean method to extract types from __VA_ARGS__ and use them to fill template method or structure definitions? Thanks in advance

I have the following problem:

my macro definition:

#define MY_MACRO(topic, callback_name, message_type, ...) \
    Callback_data<message_type, ##__VA_ARGS__> callback_name##_data(callback_name, topic); \
    Handler::add_callback<message_type, ##__VA_ARGS__>(callback_name##_data)

my macro call:

MY_MACRO("/my_topic_1", callback_1, bool, int a, int b);

what I'd like my macro writes:

Callback_data<bool, int, int> callback_1_data(callback_1, "/my_topic_1");
Handler::add_callback<bool, int, int>(callback_1_data);

what my macro actually writes:

Callback_data<bool,int a, int b> callback_1_data(callback_1, "/my_topic_1"); 
Handler::add_callback<bool,int a, int b>(callback_1_data);
//! error on both lines, template filling expecting only type definitions !

PS : If anyone knows of a modern way to do the same thing without using macros, I'm interested too!

  • Why do you give the `int`s names but not the `bool`? Just do like you do with the bool parameter and use `MY_MACRO("/my_topic_1", callback_1, bool, int, int);` – NathanOliver Sep 23 '22 at 13:18
  • [@NathanOliver](https://stackoverflow.com/users/4342498/nathanoliver) Unfortunately I have to see the name for the first line call (which requires the variable name implicitly). – Gabriel De Champeaux Sep 23 '22 at 13:35
  • [@NathanOliver](https://stackoverflow.com/users/4342498/nathanoliver) I'm truly sorry, your are perfectly right !! Thanks a lot ! – Gabriel De Champeaux Sep 23 '22 at 13:45

0 Answers0