Just to see how it worked, I looked at the libstdc++ implementation of std::common_type
in the header type_traits
. I have to admit that I don\'t really
The third version uses the conditional operator to determine the common type. Its rules are described at quite a length in section 5.16 of the standard, so I'm not sure I should copy them here.
Simply put, the expression:
boolean-expression ? second-operand : third-operand
has a "common type" of the second and third operands, if such exists. The decltype
specifier is then used to "convert" the expression into a type-specifier.