decltype on type expressions

c++, decltype, templates

Solution

The Holy Standard provides `std::declval` for exactly this purpose:

typedef decltype (declval<T1>()+declval<T2>()) sum_type;

Include the `<utility>` header.

Problem

Is there any way to avoid the dummy functions in the following example? ``` template<class T1, class T2> struct A { static T1 T1_ (); static T2 T2_ (); typedef decltype (T1_ () + T2_ ()) sum_type; }; ``` I would like to write ``` typedef decltype (T1+T2) sum_type; ``` but that's not possible since `T1` and `T2` are types, not variables. Is my above solution really the easiest one possible?

Original source