I would like to implement a template function that compares two variables of two types (T1 and T2). These types are two random unsigned or signed integer types.
To be able to compare them correctly I need to cast both of them to a 'bigger' integer type (T3). Promotion rules for signed/unsigned comparison unfortunately always promote to the unsigned type.
So how can I find a type T3 in C++11/C++14/C++17 that covers two integer types T1 and T2, no matter which size and signedness they have? If this isn't possible, is there an other solution to build a template based comparison function that works reliably with any integer combination?
T1is the largest signed type andT2is its unsigned counterpart. - AnT