in book “The Cpp standard library”, 2nd edition, by Nicolai M. Josuttis, says (5.4, p.125) that definition of struct common type is following:
template <typename T1, typename T2>
struct common_type<T1,T2> {
typedef decltype(true ? declval<T1>() : declval<T2>()) type;
};
I have serious problems to believe that this is correct definition of common_type. Reason:
typedef decltype(true ? declval<T1>() : declval<T2>()) type;//As far as I understand this will always pick second operand, declval<T1>(), due to the fact that there is 'true' value. Am I right?
It’s all about conditional operator. It isn’t selection statement like if or switch.
5.16 paragraph of ISO C++11 standard:
So, it doesn’t matter that decltype contains true condition, compiler have to choose common type as result.
UPD: 5.16 contains further description of correct behavior, you should see it for completely understanding entire process. But for your particular question: