There is no such thing as a package extension for variable arrays, as well as for variable templates.
However, you can use Boost.Preprocessor (or its methods).
If you don't need any commas between elements, use
#include <boost/preprocessor/seq/for_each.hpp> #include <boost/preprocessor/variadic/to_seq.hpp> #define ID_OP(_, func, elem) func(elem) #define APPLY_TO_ALL(func, ...) \ BOOST_PP_SEQ_FOR_EACH( \ ID_OP, func, \ BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \ ) // example call: #define SomeTransformation(x) #x // stringize the argument APPLY_TO_ALL(SomeTransformation, 1, 2, 3) // expands to "1" "2" "3"
Demo With commas:
#include <boost/preprocessor/seq/enum.hpp> #include <boost/preprocessor/seq/transform.hpp> #include <boost/preprocessor/variadic/to_seq.hpp> #define ID_OP(_, func, elem) func(elem) #define APPLY_TO_ALL(func, ...) \ BOOST_PP_SEQ_ENUM( \ BOOST_PP_SEQ_TRANSFORM( \ ID_OP, func, \ BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \ )) // example call: APPLY_TO_ALL(SomeTransformation, 1, 2, 3) // expands to "1", "2", "3"
Demo Check the preprocessor output with g++ -std=c++11 -E -P file .
source share