#include #include #include #include #include #include #include #include // ::::::::::::::::::::::::::::::::::::::::::::::::::::: // Test du support de la STL par le compilateur // string, vector, map, complex exception // ::::::::::::::::::::::::::::::::::::::::::::::::::::: using namespace std; // -------------------------------------------------------------------- // definition d'une classe de conversion de C (complexes) <> R (reel) class convCR { public: inline convCR() { dv = 0.; dv_im = 0.; } inline convCR(float v) { dv = (double)v; dv_im = 0.; } inline convCR(double v) { dv = v; dv_im = 0.; } inline convCR(complex z) { dv = (double)z.real(); dv_im = (double)z.imag(); } inline convCR(complex z) { dv = z.real(); dv_im = z.imag(); } inline float operator= (float v) { dv = (double)v; dv_im = 0.; return v; } inline double operator= (double v) { dv = v; dv_im = 0.; return v; } inline complex operator= (complex z) { dv = (double)z.real(); dv_im = (double)z.imag(); return z; } inline complex operator= (complex z) { dv = z.real(); dv_im = z.imag(); return z; } inline operator float() const { return((float)dv); } inline operator double() const { return(dv); } inline operator complex() const { return(complex((float)dv, (float)dv_im)); } inline operator complex() const { return(complex(dv, dv_im)); } double dv; double dv_im; /* for holding imaginary part of a complex */ }; // -------------------------------------------------------------------- int main(int narg, char *arg[]) { cout << "\n :::::::: Test complex / vector et map de la stl :::::::: \n" ; int rc = 0; try { vector vi; int k; for(k=0; k<5; k++) vi.push_back(k*5); cout << " -----> vector vi.size() = " << vi.size() << endl; for(k=0; k::iterator it; cout << " -----> map msi.size() = " << msi.size() << endl; for(it=msi.begin(); it!=msi.end(); it++) cout << " S= " << (*it).first << " I=" << (*it).second << endl; cout << " ----> complex numbers and convCR : " << endl; complex z,z1(2,2),z2(3,-1); complex zd,zd1(2.5,2.5),zd2(3.3,-1); cout << " complex: z1=" << z1 << " z2=" << z2 << " z1+z2=" << z1+z2 << endl; cout << " complex: z1=" << zd1 << " z2=" << zd2 << " zd1+zd2=" << zd1+zd2 << endl; convCR czr, czr1(z1), czr2(zd2), czr3; #if defined(__GNUG__) && (__GNUC__ < 3) complex za; complex zb,zc; za = czr1; zb = czr1; zc = czr2; cout << " GNUG_Version: __GNUC__ = " << __GNUC__ << endl; cout << " convCR: za=(zb)=czr1" << za << " zc=" << zc << " zb+zc=" << zb+zc << endl ; #else cout << " convCR: czr1(z1)" << (complex)czr1 << " czr2(z2)" << (complex)czr2 << " czr1+czr2= " << (complex)czr2+(complex)czr1 << endl; #endif } catch(exception exc){ // Classe de base des exception standard - // La methode what() n'est pas forcement conforme a la norme string msg = exc.what(); cerr << " Catched exception : msg= " << msg << endl; rc = 98; } catch (...) { cerr << " Catched Unknown exception ! " << endl; rc = 99; } cout << " ::::::::: Exiting from vecmapstl.cc ::::::::: \n" << endl; exit(rc); }