get_wider<int, float> == float - what is it called in boost?

Hi! I may have posted the first half of this question once, sorry for that! : ) The question in short: which boost library enables me to get the "wider" datatype of two, such that get_wider<int, float>::type will be float, and get_wider<float, int>::type will also be float. Hopefully get_wider<int, string>::type will generate a compile-time error, since the two are not convertible to each other. More verbosely: Let's take a look at this simple functor class: template<typename TLeft, typename TRight> struct mixed_plus : public binary_function<TLeft, TRight, TLeft> // result_type: bad solution! { result_type operator() (first_argument_type left, second_argument_type right) const { return left + right; } }; All is fine if I write this: cout << mixed_plus<float, int>()(5.5, 5) << endl; OUTPUT: 11.5 (as expected) But when I write this: cout << mixed_plus<int, float>()(5, 5.5) << endl; OUTPUT: 10 (as expected but not as intended) I vaguely remember that there is a boost library that is able to generate the "wider" data type of two data type, with the help of which I would be able to have the result_type typedef always the appropriate one.

"Agoston Bejo" <gusz1@freemail.hu> escribió en el mensaje news:cp071h$fog$2@sea.gmane.org...
Hi! I may have posted the first half of this question once, sorry for that! : )
The question in short: which boost library enables me to get the "wider" datatype of two, such that get_wider<int, float>::type will be float, and get_wider<float, int>::type will also be float. Hopefully get_wider<int, string>::type will generate a compile-time error, since the two are not convertible to each other.
#include <boost/numeric/conversion/conversion_traits.hpp> boost::numeric::conversion_traits<int,float>::supertype For info about this: http://www.boost.org/libs/numeric/conversion/doc/conversion_traits.html HTH Fernando Cacciola
participants (2)
-
Agoston Bejo
-
Fernando Cacciola