fork download
  1. #include <iostream>
  2.  
  3. template<typename T>
  4. constexpr int int_n(T x){
  5. return 1;
  6. }
  7.  
  8. template<typename T, typename... m>
  9. constexpr int int_n(T x,m... hvost){
  10. return 1+int_n(hvost...);
  11. }
  12. constexpr int str_n( const char* s){
  13. int u=0;
  14. while(*s!=0){
  15. if (*s=='%') u++;
  16. s++;
  17. }
  18. return u;
  19. }
  20.  
  21. #define print_test(a,b...) {static_assert(int_n(b)==str_n(a),"err");printf(a,b);}
  22.  
  23. int main(int argc, char** argv)
  24. {
  25.  
  26.  
  27. print_test("%d %d %c %d %d\n",7,4,'d',123,0);
  28. print_test("%d %c %d %d\n",7,4,'d',123,0);
  29. print_test("%d %d\n",4,'d');
  30.  
  31. }
Compilation error #stdin compilation error #stdout 0s 15232KB
stdin
Standard input is empty
compilation info
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);
       ^~~~~~~~~~
stdout
Standard output is empty