1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template <class T>
inline T mmax(const T &a, const T &b){ return (a>b) ? a : b; }
template <class T>
inline T mmax(vector<T> &v){ return *mmaxc(v.begin(),v.end()); }
template <class itType>
itType mmaxc(itType first, itType last);
int main()
{
int a=5,b=6, iarr[]={5,4,9,65,21,1000,44,6};
double c=12.4,d=5.32, darr[]={5.22,1000.1,53.21,12.5};
string s="sadf",t="jwewet", sarr[]= "asfgh","sg43g","Asg","hdsadh","zdsadhshdash"};
vector<int> ivec(iarr, iarr+8);
vector<double> dvec(darr, darr+4);
vector<string> svec(sarr, sarr+5);
cout << "int: " << mmax(a,b) << endl
<< "dbl: " << mmax(c,d) << endl
<< "str: " << mmax(s,t) << endl
<< "aint: " << *mmaxc(iarr,iarr+8) << endl
<< "adbl: " << *mmaxc(darr,darr+4) << endl
<< "astr: " << *mmaxc(sarr,sarr+5) << endl
<< "vint: " << mmax(ivec) << endl
<< "vdbl: " << mmax(dvec) << endl
<< "vstr: " << mmax(svec) << endl
;
return 0;
}
template <class itType>
itType mmaxc(itType first, itType last)
{
itType m=first;
while(++first!=last){ *m=mmax(*m,*first); }
return m;
}
| |