|
Boost Users : |
Subject: Re: [Boost-users] find the largest/most precise of two types
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-05-20 11:51:41
AMDG
Alex Flint wrote:
> I have a bunch of functions that accept two numeric arguments. In the
> case that the types of these arguments are different I want to figure
> out what the return type should be. The rule I would like to use is
> that the largest of the two types should be used for internal
> computations and the return type.
>
> f(someFloat, someDouble) -> double
> f(someFloat, someFloat) -> float
> f(someInt, someFloat) -> float
>
> Is there a way I can do this, perhaps with boost's type_traits?
>
A quick glance through type_traits didn't show anything.
How does this work:
#include <boost/typeof/typeof.hpp>
template<class T0, class T1>
struct promote {
BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, (T0() + T1()))
typedef typename nested::type type;
};
In Christ,
Steven Watanabe
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