我想创建一个可变参数宏,可以在其中编写“ gen(X,Y,Z)”而不是模板
如果我注释掉gen_3宏,则vs会告诉扩展“ gen(X,Y,Z)”将是“ gen_3(X,Y,Z)”,这很好。但是,如果我不评论扩展名是“ template
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME ## _, NUM )
#define COMPOSE( NAME, ARGS ) NAME ARGS
#define GET_COUNT( _0, _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define EXPAND() ,,,,,, // 6 commas (or 7 empty tokens)
#define VA_SIZE( ... ) COMPOSE( GET_COUNT, (EXPAND __VA_ARGS__ (), 0, 6, 5, 4, 3, 2, 1) )
#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
#define gen(...) VA_SELECT( gen, __VA_ARGS__ )
#define gen_0() template<>
#define gen_1(A) template<typename A>
#define gen_2(A, B) template<typename A, typename B>
#define gen_3(A, B, C) template<typename A, typename B, typename C>
#define gen_4(A, B, C, D) template<typename A, typename B, typename C, typename C>
template<typename A, typename B, typename C> //original
struct S0
{
};
gen(X, Y, Z) //new //does not work :(
struct S1
{};
int main()
{
}