#include #include #include // not sure that this include should be here, but g++ demands it #include #include #include using namespace std; void pident(ostream &os, int ilvl) { for(int i=0;i void printxmlmembers(ostream &os, int ilvl, T &&x, TailT &&...tail) { static unordered_map namelookup {{type_index(typeid(int)),"int"}, {type_index(typeid(double)),"double"}, {type_index(typeid(char *)),"string"}, {type_index(typeid(const char *)),"string"}, {type_index(typeid(char * const)),"string"}, {type_index(typeid(const char * const)),"string"}, {type_index(typeid(char)),"char"}}; pident(os,ilvl); const char *tname = namelookup[type_index(typeid(T))]; os << "<" << tname; stringstream ss; ss << x; if (ss.str().length()>10) { os << ">" << ss.str() << "<\\"; os << tname << ">" << endl; } else os << " value=\"" << ss.str() << "\"\\>" << endl; printxmlmembers(os,ilvl,forward(tail)...); } template void printxml(ostream &os, int ilvl, ST &&name, Ts &&...x) { pident(os,ilvl); os << "<" << name << ">" << endl; printxmlmembers(os,ilvl+1,forward(x)...); // note syntax here pident(os,ilvl); os << "<\\" << name << ">" << endl; } int main(int argc, char **argv) { int a=1; const char *s = "hello"; double d = 4.53; char c = '!'; printxml(cout,0,"testpack",a,s,d,c,a,a,a, (const char *)"a really really really long string",5); }