#include <iostream>
#include <cstring>
using namespace std;
template <typename T>
T maxn(const T * cArr, const int iSize);
template <>
char * maxn<char*>(char * const * cArr, const int iArrSize);
int main(void){
int iTest = 0;
double dTest = 0.0;
int iArr[6] = {1, 2, 3, 7, 5, 6};
int iArrSize = (sizeof(iArr))/(sizeof(iArr[0]));
double dArr[4] = {1.0, 2.0, 3.0, 4.0};
int dArrSize = (sizeof(dArr))/(sizeof(dArr[0]));
const char * cNames[5] = {"Mona", "Elzushka", "Leopold", "Burger", "Arny"};
int iSizeOf = (sizeof(cNames)) / (sizeof(cNames[0]));
iTest = maxn(iArr, iArrSize);
cout << "Test maxn(int) = " << iTest << endl;
dTest = maxn(dArr, dArrSize);
cout << "Test maxn(double) = " << dTest << endl;
const char * cTest = maxn(cNames, iSizeOf);
cout << "Test maxn(char) = " << cTest << endl;
return 0;
}
template <typename T>
T maxn(const T* tArr, const int iSize)
{
T tMax = tArr[0];
for (int i = 0; i < iSize; i++)
{
if (tArr[i] > tMax){
tMax = tArr[i];
}
}
cout << "MAXN T " << endl;
return tMax;
}
template <>
char * maxn<char*>(char * const * cArr, const int iArrSize)
{
char * cMaxLen = &cArr[0][0];
for (int i = 0; i < iArrSize; i++)
{
if (strlen(&cArr[i][0]) > strlen(cMaxLen)){
cMaxLen = &cArr[i][0];
}
}
cout << "MAXN C " << endl;
return cMaxLen;
}
#include <iostream>
#include <cstring>
using namespace std;
template <typename T>
T maxn(const T * cArr, const int iSize);
template <>
char const* maxn<char const*>(char const * const * cArr, const int iArrSize);
int main(void){
int iTest = 0;
double dTest = 0.0;
int iArr[6] = {1, 2, 3, 7, 5, 6};
int iArrSize = (sizeof(iArr))/(sizeof(iArr[0]));
double dArr[4] = {1.0, 2.0, 3.0, 4.0};
int dArrSize = (sizeof(dArr))/(sizeof(dArr[0]));
const char * cNames[5] = {"Mona", "Elzushka", "Leopold", "Burger", "Arny"};
int iSizeOf = (sizeof(cNames)) / (sizeof(cNames[0]));
iTest = maxn(iArr, iArrSize);
cout << "Test maxn(int) = " << iTest << endl;
dTest = maxn(dArr, dArrSize);
cout << "Test maxn(double) = " << dTest << endl;
const char * cTest = maxn(cNames, iSizeOf);
cout << "Test maxn(char) = " << cTest << endl;
return 0;
}
template <typename T>
T maxn(const T* tArr, const int iSize)
{
T tMax = tArr[0];
for (int i = 0; i < iSize; i++)
{
if (tArr[i] > tMax){
tMax = tArr[i];
}
}
cout << "MAXN T " << endl;
return tMax;
}
template <>
char const* maxn<char const*>(char const * const * cArr, const int iArrSize)
{
const char * cMaxLen = &cArr[0][0];
for (int i = 0; i < iArrSize; i++)
{
if (strlen(&cArr[i][0]) > strlen(cMaxLen)){
cMaxLen = &cArr[i][0];
}
}
cout << "MAXN C " << endl;
return cMaxLen;
}