/* Apprend std::tie On voit que ça simplifie le code redondant pour comparer plusieurs champs. La performance est la même. */ #include #include #include #include #include #include #include "getnow.h" using namespace std; struct A{ int a; string b; int c; A(int _a, const char *_b, int _c) :a(_a),b(_b),c(_c) { } bool operator < (const A &n) { bool ret = false; if (a < n.a){ ret = true; }else if (a == n.a){ if (b < n.b){ ret = true; }else if (b == n.b){ ret = c < n.c; } } return ret; } }; struct A_tie{ int a; string b; int c; A_tie(int _a, const char *_b, int _c) :a(_a),b(_b),c(_c) { } bool operator < (const A_tie &n) { return tie(a,b,c) < tie(n.a,n.b,n.c); } }; struct B_tie{ int a; string b; int c; int d; B_tie(int _a, const char *_b, int _c, int _d) :a(_a),b(_b),c(_c),d(_d) { } bool operator < (const A_tie &n) { return tie(a,b,c,d) < tie(n.a,n.b,n.c,d); } }; template void test(T &a, T &b, unsigned int nbrep) { long long start = getnow(); unsigned long count = 0; for (unsigned i=0; i int main (int argc, char *argv[]) { glocal int ret = -1; glocal unsigned nbrep = 1; glocal.ret = (argc,argv); setproginfo ("","0.0","..."); setarg ('n',"nbrep","Nombre de repetition",glocal.nbrep,false); int ret = -1; { A a(1,"allo",2); A b(1,"allo",1); test (a,b,glocal.nbrep); } { A_tie a(1,"allo",2); A_tie b(1,"allo",3); test (a,b,glocal.nbrep); } return ret; return glocal.ret; }