I have two lists:
#define LIST1 {1, 2, 3}
#define LIST2 {4, 5, 6}
and using C++ macros I would like to write something like this:
// Obviously doesn't work
#define MERGE LIST1 ## LIST2
int my_array[] = MERGE;
to yield:
int my_array[] = {1, 2, 3, 4, 5, 6};
during compile-time.
Is something like this possible? There are other questions concerning this with strings, however I can't figure out for the life of me how to do this with non-string array declarations.
Edit: I certainly would prefer to not use macros, and would prefer that the list format be different as well. Unfortunately, the header file that contains these list definitions isn’t a file that I can edit.
Don't use macros unless there is no other option, prefer templates. They are typesafe.
For example you can make a compile time evaluated function (constexpr) that merges two lists (arrays) and returns an array.