c++ - Template with more parameters -


I'm trying to do a multi debug function. It works but now I would like to add 2 things:

  1. Work it with a variable number of different parameters.
  2. As the name of the output, add: example: a: 42b [0]: 54

      template & lt; Bool B & gt; Struct Print {}; The template's & lt; & Gt; Struct Print & lt; True & gt; {Template & lt; Class T & gt; Fixed-do doit (TA) {cout & lt; & Lt; A & lt; & Lt; Endl; }}; The template's & lt; & Gt; Struct Print & lt; False & gt; {Template & lt; Class T & gt; Fixed int do_it (T & A) (for (int _n ((int) ((a) .ize ())) - 1), i (0); i & lt; = _n; i ++ Cout & lt;  gt; b.push_back (54); debug (a); // works debug (b); // works debug (a, b); // this is what i am trying to do Return 0;}  

PS: C ++ 11

Just add variable names and arguments Focusing on the aspect of supporting arbitrary numbers, you can use freedy macros to capture names and diverse templates to capture all the arguments, which does not attempt to integrate writing sequences, but it is easy From the operator , you can format the condition rather than conditionally. Here is an example code:

  #include & lt; Iostream & gt; # Include & lt; Sstream & gt; #include & lt; String & gt; # Include & lt; Tupal & gt; # Include & lt; Vector & gt; Template & lt; Int i, int N & gt; Structure Debugger {Template & lt; Typename ARGS & gt; Static Zero Print (std :: vector & lt; std :: string & gt; cons & amp; name, args const & amp; alg) {std :: cout & lt; & Lt; Name [i] & lt; & Lt; '=' & Lt; & Lt; Std :: Mill & lt; I & gt; (Args) & lt; & Lt; ''; Debugger & lt; I + 1, N & gt; :: print (name, args); }}; Template & lt; Int N & gt; Strait Debugger & lt; N, N & gt; {Template & lt; Typename rgs & gt; Static zero print (std :: vector & lt; std :: string & gt; const & amp; args const & amp;;}}; Template & lt; Typename ... n, typename ... a & gt; Zero print_debug (char const * str, std :: tuple & lt; a ... & gt; constant & egg) {std :: istringstream in (str); Std :: vector & lt; Std :: string & gt; Name; (Std :: string name; std :: getline (in & gt; & gt; std :: ws, name, ',')); {names.push_back (name); } Debugger & lt; 0, std :: tuple_size & lt; Std :: tuple & lt; A ... & gt; :: Price & gt; :: print (name, args); Std :: cout & lt; & Lt; '\ N'; } #define debug (...) print_debug (#__ VA_ARGS__, std :: tie (__VA_ARGS__)) int main () {int i (17); Double D (3.14); Debug (I, D); }  

Comments