Boost logo

Boost Users :

From: Agoston Bejo (gusz1_at_[hidden])
Date: 2004-12-05 18:53:20


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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net