#include <type_traits>
#include <iostream>
using namespace std;
// Expand
#define PP_EXPAND(X) X
// Counter Arguments count
#define PP_ARG_COUNT(...) PP_EXPAND( PP_ARG_POPER(__VA_ARGS__, 5, 4, 3, 2, 1, 0) )
#define PP_ARG_COUNT2(...) PP_ARG_POPER(__VA_ARGS__, 5, 4, 3, 2, 1, 0)
#define PP_ARG_POPER(_1, _2, _3, _4, _5, N, ...) N
int main()
{
cout << PP_ARG_COUNT(1, 2, int) << endl;
cout << PP_ARG_COUNT2(1, 2, int) << endl;
cout << PP_ARG_POPER(1, 2, int, 5, 4, 3, 2, 1 0) << endl;
return 0;
}
i have compile this code under visual studio 2013, it output:
3
1
3
why this macro need a PP_EXPAND, and PP_ARG_COUNT2 it not work well?