#include <iostream>
template<typename T>
constexpr int int_n(T x){
return 1;
}
template<typename T, typename... m>
constexpr int int_n(T x,m... hvost){
return 1+int_n(hvost...);
}
constexpr int str_n( const char* s){
int u=0;
while(*s!=0){
if (*s=='%') u++;
s++;
}
return u;
}
#define print_test(a,b...) {static_assert(int_n(b)==str_n(a),"err");printf(a,b);}
int main(int argc, char** argv)
{
print_test("%d %d %c %d %d\n",7,4,'d',123,0);
print_test("%d %c %d %d\n",7,4,'d',123,0);
print_test("%d %d\n",4,'d');
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGU8dHlwZW5hbWUgVD4KY29uc3RleHByIGludCBpbnRfbihUIHgpewpyZXR1cm4gMTsKfQoKdGVtcGxhdGU8dHlwZW5hbWUgVCwgdHlwZW5hbWUuLi4gbT4KY29uc3RleHByIGludCBpbnRfbihUIHgsbS4uLiBodm9zdCl7CnJldHVybiAxK2ludF9uKGh2b3N0Li4uKTsKfQpjb25zdGV4cHIgaW50IHN0cl9uKCBjb25zdCBjaGFyKiBzKXsKICAgaW50IHU9MDsKICAgd2hpbGUoKnMhPTApewogICAgICBpZiAoKnM9PSclJykgdSsrOwogICAgICBzKys7CiAgIH0KICAgcmV0dXJuIHU7Cn0KCiNkZWZpbmUgcHJpbnRfdGVzdChhLGIuLi4pICB7c3RhdGljX2Fzc2VydChpbnRfbihiKT09c3RyX24oYSksImVyciIpO3ByaW50ZihhLGIpO30KCmludCBtYWluKGludCBhcmdjLCBjaGFyKiogYXJndikKewoKCiAgICAgIHByaW50X3Rlc3QoIiVkICVkICVjICVkICVkXG4iLDcsNCwnZCcsMTIzLDApOwogICAgICBwcmludF90ZXN0KCIlZCAlYyAlZCAlZFxuIiw3LDQsJ2QnLDEyMywwKTsKICAgICAgcHJpbnRfdGVzdCgiJWQgJWRcbiIsNCwnZCcpOwoKfQ==
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:21:30: error: static assertion failed: err
#define print_test(a,b...) {static_assert(int_n(b)==str_n(a),"err");printf(a,b);}
^
prog.cpp:28:7: note: in expansion of macro ‘print_test’
print_test("%d %c %d %d\n",7,4,'d',123,0);
^~~~~~~~~~