Macro which can determine size of tuple passed as argument

Hi, I am trying to implement a macro which can determine size of tuple passed as argument. My first idea was to 1) remove parentheses from tuple using variadic macro (which I can afford for) 2) complement tuple elements list with "filler and marker" sequence 3) scan resulting arguments list right-to-left. Straightforward 1-3-arguments version using variadic macros and boost.preprocessor looks like: #include <boost/preprocessor/control/if.hpp> #define M4(a1,a2,a3,a4,...) BOOST_PP_IF(a4,3,M3(a1,a2,a3)) #define M3(a1,a2,a3) BOOST_PP_IF(a3,2,M2(a1,a2)) #define M2(a1,a2) BOOST_PP_IF(a2,1,M1(a1)) #define M1(a1) 0 #define M(...) M4(__VA_ARGS__,1,0,0,0) #define T(t) M t After preprocessing these invocations T((a,b,c)) T((a,b)) T((a)) expand to: 3 2 1 Unfortunately these macros do not allow to discriminate between 1 and 0 -element tuples: both T((a)) and T(()) invocations expand to 1 instead of 1 and 0 correspondingly. It seems that chosen approach might work if I had any way to append different filler to non-empty and empty tuple: with and without leading comma separator. Could you please advise me if it is possible to implement a macro which can determine size of tuple passed as argument ? Does boost.preprocessor allow this ? Can variadic macros be of any help ? Cheers, Yuri
participants (1)
-
6orkup