//basics/max2.cpp
#include <iostream>
using namespace std;
namespace rawu
{
inline int const& max(int const& a ,int const& b)
{
cout<<" not template"<<endl;
return a < b ? b : a;
}
template<typename T>
inline T const& max(T const& a, T const& b)
{
cout<<" template2 "<<endl;
return a < b ? b : a;
}
template<typename T>
inline T const& max(T const& a, T const& b, T const& c)
{
cout<<" template3 "<<endl;
return max ( max(a,b) , c ) ;
}
template<typename T3 ,typename T1 , typename T2>
inline T3 max(T1 const& a ,T2 const& b) //inline T3 const& max(T1 const& a ,T2 const& b) -- The address of a local variable or temporary is used in a return expression.
{
cout<<" diff type template2"<<endl;
return a < b ? b : a;
}
}
int main(void)
{
cout<<rawu::max(7,43,23)<<endl; //call 2 not template
cout<<rawu::max<int>(7,43,23)<<endl; // call 2 not template
cout<<rawu::max<>(7,43)<<endl; //call 1 template2
cout<<rawu::max('s',34.2)<<endl; //call 1 not template
cout<<rawu::max<double>('s',34.2)<<endl; //call diff type template2
}
#include <iostream>
using namespace std;
namespace rawu
{
inline int const& max(int const& a ,int const& b)
{
cout<<" not template"<<endl;
return a < b ? b : a;
}
template<typename T>
inline T const& max(T const& a, T const& b)
{
cout<<" template2 "<<endl;
return a < b ? b : a;
}
template<typename T>
inline T const& max(T const& a, T const& b, T const& c)
{
cout<<" template3 "<<endl;
return max ( max(a,b) , c ) ;
}
template<typename T3 ,typename T1 , typename T2>
inline T3 max(T1 const& a ,T2 const& b) //inline T3 const& max(T1 const& a ,T2 const& b) -- The address of a local variable or temporary is used in a return expression.
{
cout<<" diff type template2"<<endl;
return a < b ? b : a;
}
}
int main(void)
{
cout<<rawu::max(7,43,23)<<endl; //call 2 not template
cout<<rawu::max<int>(7,43,23)<<endl; // call 2 not template
cout<<rawu::max<>(7,43)<<endl; //call 1 template2
cout<<rawu::max('s',34.2)<<endl; //call 1 not template
cout<<rawu::max<double>('s',34.2)<<endl; //call diff type template2
}