#include <iostream>
#include <cstring>
using namespace std;
template<int size, class T>
T min2(const T (&a)[size])
{
cout << "min<T>" << endl;
T m = a[0];
for (int i = 0; i < size; i++)
if(a[i] < m) m = a[i];
return m;
}
template<int size>
char* min2(char* (&a)[size])
{
cout << "min<char*>" << endl;
char* m = a[0];
for (int i=0; i < size; i++)
if (strcmp(a[i], m) < 0) m = a[i];
return m;
}
int main()
{
int ia[] = { 0, 1 };
int imin = min2(ia);
cout << "imin = " << imin << endl;
char* is[] = { "0", "1" };
char* smin = min2(is);
cout << "smin = " << smin << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlPGludCBzaXplLCBjbGFzcyBUPgpUIG1pbjIoY29uc3QgVCAoJmEpW3NpemVdKQp7Cgljb3V0IDw8ICJtaW48VD4iIDw8IGVuZGw7CiAgICBUIG0gPSBhWzBdOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplOyBpKyspCiAgICAgICAgaWYoYVtpXSA8IG0pIG0gPSBhW2ldOwogICAgcmV0dXJuIG07Cn0KCnRlbXBsYXRlPGludCBzaXplPgpjaGFyKiBtaW4yKGNoYXIqICgmYSlbc2l6ZV0pCnsgICAgICAgICAgICAgICAgICAgICAgICAgICAKCWNvdXQgPDwgIm1pbjxjaGFyKj4iIDw8IGVuZGw7CiAgICBjaGFyKiBtID0gYVswXTsgICAgICAgICAgICAKICAgIGZvciAoaW50IGk9MDsgaSA8IHNpemU7IGkrKykgICAKICAgICAgICBpZiAoc3RyY21wKGFbaV0sIG0pIDwgMCkgbSA9IGFbaV07CiAgICByZXR1cm4gbTsKfQoKaW50IG1haW4oKQp7CglpbnQgaWFbXSA9IHsgMCwgMSB9OwogICAgaW50IGltaW4gPSBtaW4yKGlhKTsKICAgIGNvdXQgPDwgImltaW4gPSAiIDw8IGltaW4gPDwgZW5kbDsKCgljaGFyKiBpc1tdID0geyAiMCIsICIxIiB9OwogICAgY2hhciogc21pbiA9IG1pbjIoaXMpOwogICAgY291dCA8PCAic21pbiA9ICIgPDwgc21pbiA8PCBlbmRsOwoJCglyZXR1cm4gMDsKfQ==