Changeset 1863 in Sophya for trunk/Eval/COS/vecmapstl.cc
- Timestamp:
- Jan 18, 2002, 9:58:50 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Eval/COS/vecmapstl.cc
r1571 r1863 8 8 #include <vector> 9 9 #include <map> 10 #include <complex> 10 11 12 // ::::::::::::::::::::::::::::::::::::::::::::::::::::: 13 // Test du support de la STL par le compilateur 14 // string, vector<T>, map<T>, complex<T> exception 15 // ::::::::::::::::::::::::::::::::::::::::::::::::::::: 16 11 17 using namespace std; 12 18 19 // -------------------------------------------------------------------- 20 // definition d'une classe de conversion de C (complexes) <> R (reel) 21 class convCR { 22 public: 23 inline convCR() { dv = 0.; dv_im = 0.; } 24 inline convCR(float v) { dv = (double)v; dv_im = 0.; } 25 inline convCR(double v) { dv = v; dv_im = 0.; } 26 inline convCR(complex<float> z) { dv = (double)z.real(); dv_im = (double)z.imag(); } 27 inline convCR(complex<double> z) { dv = z.real(); dv_im = z.imag(); } 28 inline float operator= (float v) { dv = (double)v; dv_im = 0.; return v; } 29 inline double operator= (double v) { dv = v; dv_im = 0.; return v; } 30 inline complex<float> operator= (complex<float> z) 31 { dv = (double)z.real(); dv_im = (double)z.imag(); return z; } 32 inline complex<double> operator= (complex<double> z) 33 { dv = z.real(); dv_im = z.imag(); return z; } 34 35 inline operator float() const { return((float)dv); } 36 inline operator double() const { return(dv); } 37 inline operator complex<float>() const { return(complex<float>((float)dv, (float)dv_im)); } 38 inline operator complex<double>() const { return(complex<float>(dv, dv_im)); } 39 40 double dv; 41 double dv_im; /* for holding imaginary part of a complex */ 42 }; 43 // -------------------------------------------------------------------- 13 44 14 45 int main(int narg, char *arg[]) 15 46 { 16 cout << "\n ---- Test vector et map de la stl ---\n" ;47 cout << "\n :::::::: Test complex / vector et map de la stl :::::::: \n" ; 17 48 int rc = 0; 18 49 try { … … 20 51 int k; 21 52 for(k=0; k<5; k++) vi.push_back(k*5); 22 cout << " vector<int> vi.size() = " << vi.size() << endl;53 cout << " -----> vector<int> vi.size() = " << vi.size() << endl; 23 54 for(k=0; k<vi.size(); k++) 24 55 cout << "vi[" << k << "]= " << vi[k] << endl; … … 29 60 msi["Douze"] = 12; 30 61 map<string, int>::iterator it; 31 cout << " map<string, int> msi.size() = " << msi.size() << endl;62 cout << " -----> map<string, int> msi.size() = " << msi.size() << endl; 32 63 for(it=msi.begin(); it!=msi.end(); it++) 33 64 cout << " S= " << (*it).first << " I=" << (*it).second << endl; 65 cout << " ----> complex numbers and convCR : " << endl; 66 complex<float> z,z1(2,2),z2(3,-1); 67 complex<double> zd,zd1(2.5,2.5),zd2(3.3,-1); 68 cout << " complex<float>: z1=" << z1 << " z2=" << z2 69 << " z1+z2=" << z1+z2 << endl; 70 cout << " complex<double>: z1=" << zd1 << " z2=" << zd2 71 << " zd1+zd2=" << zd1+zd2 << endl; 72 convCR czr, czr1(z1), czr2(zd2), czr3; 73 cout << " convCR: czr1(z1)" << (complex<float>)czr1 74 << " czr2(z2)" << (complex<double>)czr2 75 << " czr1+czr2= " << (complex<double>)czr2+(complex<double>)czr1 << endl; 34 76 } 35 77 catch(exception exc){ … … 45 87 } 46 88 47 cout << " ------ Exiting from vecmapstl.cc -----------\n" << endl;89 cout << " ::::::::: Exiting from vecmapstl.cc ::::::::: \n" << endl; 48 90 exit(rc); 49 91 }
Note:
See TracChangeset
for help on using the changeset viewer.