template<class A, class B, class ReturnType>
inline ReturnType const & GREATERfunction( A &a, B &b, ReturnType const
&return_value = ( (a) > (b) ? (a) : (b) ) )
{
return return_value;
}
Well first thing I've noticed:
If the calling function supplies the argument "return_value", then the
temporary object is local to the calling function, whilst (correct me if I'm
wrong) if my default argument were to work, then the object would be local
to the GREATERfunction, right?
Nice try (seriously) but unfortunatly no banana:
int f( int a, int b = a );
int main() {}
The above should illustrate the problem. In short default
arguments aren't allowed to be dependant on other arguments.
This truly is bullshit. I'm surprised I even had to come this far.
Why in the name of God would a compiler not be able to determine from the
following, the return type:
template<class ReturnType, class A, class B>
inline ReturnType const & MAX(A& a, B& b)
{
return ( (a) > (b) ? (a) : (b) );
}
It's painfully obvious in the above what the return type is! I think this is
something that should be submitted to the Standard commitee.
(BTW: I'm not looking for a way to simply turn MAX into a function, I'm
trying to find a universal way to turn any macro function into a proper
function.)
-JKop