How could we measured the relationship between types and binary files generated by
compilers?
1 2 3 4 5 6 7 8 9 10 11 12 13
template<typename T>
T Max(T const A, T const B)
{
return A > B ? A : B;
}
void testMax()
{
int a = 5, b = 10;
double c = 44.4, d = 33.23;
Max(a, b);
Max(c, d);
}
is same as
1 2 3 4 5 6 7 8 9
int Max(intconst A, intconst B)
{
return A > B ? A : B;
}
double Max(doubleconst A, doubleconst B)
{
return A > B ? A : B;
}
Ok, I know I could ask the compiler to generate the "Max" I need
and it is same as handcrafted codes
but what about this
class NullType;
template<typename T, typename U>
class Typelist
{
typedef T Head;
typedef U Tail;
};
template<typename TList>
class length;
template<>
class length<NullType>
{
public :
enum{ Value = 0 };
};
template<typename Head, typename Tail>
class length<Typelist<Head, Tail> >
{
public :
enum { Value = 1 + length<Tail>::Value };
};
what we really get is an enumerator constant "Value"
would those recursive steps generate binary codes too?
Or compiler would optimize it?
Thanks