I am trying to understand better when decay or not a type
#include <type_traits>
template <typename T1, typename T2> auto max_test(T1 a, T2 b) -> typename std::decay<decltype(a > b ? a: b)>::type {
return a < b ? a : b;
}
template <typename T1, typename T2> auto max_test_r(T1 a, T2 b) -> decltype(a > b ? a: b) {
return a < b ? a : b;
}
Which is the most correct version and why? Should i avoid using decays or when should i use them?
The second if flawed, thanks to Adam for the answer. The problem is that you are decltyping an lvalue.