I see what it is trying to do. But what I am confused about is this.
1 2
|
decltype(true ? std::declval<T1>()
: std::declval<T2>()
|
Within the decltype statement, the condition is given as
true. When the compiler sees that the condition is
true, won't it automatically assume the return type is the decayed type of
T1 and then won't it give an error if the condition
b < a turns out to be false and thus returns a type
T2 (assuming T1 and T2 are different types)?
Logically, it seems that this function would only work if the condition
b < a is true, because then the type is T1, and if it is not then it would give an error. I just don't understand why
decltype(true std::declval<T1>() : std::declval<T2>() first checks the body of the function and looks at the condition for the return type (
b < a ) rather than simply seeing that there is a
true inside the condition given in the decltype, thus automatically resolving to
decltype(std::declval<T1>())