This example is taken from: https://learn.microsoft.com/en-us/cpp/cpp/templates-cpp?view=msvc-160
I already tested the code can somebody tell me what it does at C20?
Why is const T& lhs used instead of const lhs used?
My answer is that it is the only thing that works. Maybe somebody can explain the inner workings?
Why is const used at all?
template <typename T> //C10
T minimum(const T& lhs, const T& rhs) //C20
{
return lhs < rhs ? lhs : rhs; //C30
}
C10= defines T as a template class=template while class is an old way to say template?
C20= what is the ampersand doing here? Why do I have to use it?
C30= conditional operator works like:
if(lhs < rhs)
{return lhs;}
else
{return rhs;}
https://learn.microsoft.com/en-us/cpp/cpp/conditional-operator-q?view=msvc-160
Does this template output any type you throw at it? I tested int, float and string. It works as expected with int and float while it does take strings it does not work as expected. Looks like it could be a sorting algorithm for ordering the display of filenames if somebody beefs it up. It only compares the first char of a string.