Hi everyone. A very simple question. I would like to know what is
better in terms of performance. I want to use a simple function to
obtain the minimum of two values. One way could be using a macro:
#define min(a,b) ((a<b)?a:b)
I thought that another way could be to use a template function:
template <class T>
T min<T a, T b>
{
if(a < b)
return a;
else
return b;
}
Any ideas on which way is better to implement? I guess that whenever I
use the template function is going to help me check at compile time.
Also, for some reason I don't like using macros. Thank you.
better in terms of performance. I want to use a simple function to
obtain the minimum of two values. One way could be using a macro:
#define min(a,b) ((a<b)?a:b)
I thought that another way could be to use a template function:
template <class T>
T min<T a, T b>
{
if(a < b)
return a;
else
return b;
}
Any ideas on which way is better to implement? I guess that whenever I
use the template function is going to help me check at compile time.
Also, for some reason I don't like using macros. Thank you.
Comment