Let's say I have a piece of code like this:
int y = 1;
int z = 1;
int x = std::min(y+1,z);
Looking at the documentation of std::min
(here), I was wondering whether the addition in the first argument of the function creates an calculation overhead, i.e. whether y+1
is possibly executed twice.
The reason for my question is that the documentation shows this as a possible implementation of std::min
:
template<class T>
const T& min(const T& a, const T& b)
{
return (b < a) ? b : a;
}
So does anyone know, whether y+1
is executed twice?