std::common_type<T1, ..., TN> is a helper template in C++ which can find the common type which all of T1 ... TN are implicitly convertible to.
According the C++ spec, a user may specialize std::common_type<T1,T2> if certain conditions apply, and:
std::common_type<T1, T2>::typeandstd::common_type<T2, T1>::typemust denote the same type.
However, common_type<T1, T2> might be a very complicated specialization for user types T1 and T2:
namespace std {
template <typename T1, complicated_constraint_of<T1> T2, ...>
struct common_type<complicated_expression_of<T1, ...>, complicated_expression_of<T2, ...>> {
using type = complicated_type_expression_of<T1,T2>;
};
}
In general, the constraint expressions are not necessarily symmetrical (for example, we might specify that T2 is a base of T1). This means that to preserve symmetry, we'd need to rewrite the entire specialization with T1 and T2 reversed, but doing that without making any mistake is extremely difficult and fragile.
How can I robustly define a commutative specialization of common_type<T1,T2> for my own types?