Is is possible to create a variadic macro that adds an expression to all arguments? For example if I write
MACRO(int, a, b, c)
I want that it get replaced with
int a, int b, int c
If possible please a solution with no external libraries
Underlying problem:
I need parts of the code where a compile time type conversion happens.
Therefore I do something similar like this:
struct Index {
Index(size_t i, size_t j) : iElem(i), iDof(j) {}
size_t iElem;
size_t iDof;
};
struct IndexOverride {
explicit IndexOverride(Index index) : iElem(index.iElem), iDof(index.iDof) {}
size_t iElem;
size_t iDof;
size_t extra;
};
#define MACRO(index, FunctionBody) { auto test = [&](IndexOverride Index) { FunctionBody; }; test(static_cast<IndexOverride>(index)); }
Now I can specify with the macro specific regions where the type of some Index changes:
Index Index(2, 3);
std::cout << typeid(Index).name();
MACRO(Index, {
std::cout << typeid(Index).name();
})
This will do it for one index. But now I want to extend the macro to multiple indices.Therefore I need add to all arguments IndexOveride and static_cast and insert in appropriate place
7