I made a template and an auto function that compare 2 values and return the smallest one. This is my code:
#include
As you have asked this question with the c++11 marker, I suppose you are using C++11. Unfortunately, the C++11 standard states that auto-type deduction (also for lambdas) is limited to a single statement.
As the ?:
operator is an expression instead of a statement, this will work while the if-else
is a statement and doesn't meet the requirements.
If you would compile this code with the C++14 standard, you will see that it should compile both cases as this limitation was removed.