The template class std::common_type
calculates a common type to a variadic type list. It is defined using the return type of the ternary operator x:y?z
recursively. From that definition it is not obvious to me, whether calculating a std::common_type<X,Y>
is associative, i. e. whether
using namespace std;
static_assert( is_same<common_type< X, common_type<Y,Z>::type >::type,
common_type< common_type<X,Y>::type, Z >::type>::value, "" );
will never throw a compile-time error for all types X
, Y
and Z
for which the is_same<...>
expression is valid.
Please note, that I'm NOT asking whether
static_assert( is_same<common_type<X,Y>::type,
common_type<Y,X>::type>::value, "" );
will ever fire. It will obviously not. The above is a whole different question.
Please note also, that the specification of std::common_type
slightly changed in C++14 and will probably change again in C++17. So the answers may be different for different versions of the standard.