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?
The Holy Standard provides std::declval for exactly this purpose:
typedef decltype (declval<T1>()+declval<T2>()) sum_type;
Include the <utility> header.
You can do this:
typedef decltype(*(T1*)0 + *(T2*)0) sum_type;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With