All parameter types must be complete. This trait is permitted to be specialized
by a user if at least one template parameter is a user-defined type. Note: Such specializations are required when only
explicit conversions are desired among the common_type
arguments.

Note that when the compiler does not support variadic templates (and the
macro BOOST_NO_VARIADIC_TEMPLATES is defined) then the maximum number of
template arguments is 3.

In a nutshell, common_type
is a trait that takes 1 or more types, and returns a type which all of the
types will convert to. The default definition demands this conversion be
implicit. However the trait can be specialized for user-defined types which
want to limit their inter-type conversions to explicit, and yet still want
to interoperate with the common_type
facility.

In the above example, "mixed-mode" complex arithmetic is allowed.
The return type is described by common_type.
For example the resulting type of adding a complex<float> and complex<double> might be a complex<double>.

Given the preceding example, one might expect common_type<A,B>::type to be C
without any intervention from the user. But the default common_type<> implementation doesn't grant that.
It is intended that clients who wish for common_type<A,B>
to be well defined to define it themselves:

Even if they appear to be close, common_type
and typeof have different
purposes. You use typeof
to get the type of an expression, while you use common_type
to set explicitly the type returned of a template function. Both are complementary,
and indeed common_type
is equivalent to decltype(declval<bool>()?declval<T>():declval<U>())

common_type
is also similar to promote_args<class ...T> in boost/math/tools/promotion.hpp,
though it is not exactly the same as promote_args either. common_type<T1,
T2>::type simply represents the result of some operation on T1 and T2,
and defaults to the type obtained by putting T1 and T2 into a conditional
statement.

It is meant to be customizable (via specialization) if this default is not
appropriate.