/* Essai de remplacer ce genre de programmation string buf; const char *prefixe = ""; for (auto s:list){ printf ("%s%s",prefixe,s); prefixe = ","; } Cela s'est retrouvé dans tlmpsql. */ #include #include #include #include #include #include using namespace std; static string & operator << (string &b, char c) { b += c; return b; } static string & operator << (string &b, int c) { b += string_f("%d",c); return b; } template void items(B &buf, const C &c, char start, char sep, char end){ bool first = true; buf += start; for (auto const &i:c){ if (first){ buf << i; first = false; }else{ buf << sep << i; } } buf += end; } int main (int argc, char *argv[]) { glocal int ret = -1; glocal.ret = (argc,argv); setproginfo ("","0.0","..."); int ret = -1; string buf; auto vec = {1,2,3,4}; items (buf,vec,'(',',',')'); printf ("items=%s\n",buf.c_str()); return ret; return glocal.ret; }