Boost logo

Boost :

Subject: Re: [boost] [chrono] type_traits/common_type and integer/ratio
From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2009-12-02 12:36:04

On Wed, Dec 2, 2009 at 10:33 AM, Howard Hinnant
<howard.hinnant_at_[hidden]> wrote:
> On Dec 1, 2009, at 1:15 PM, Michael Fawcett wrote:
>> I've needed this feature many times.  Can you explain the pros/cons of
>> common_type against Boost.Typeof?
> common_type is closer in nature to promote_args<class ...T> in boost/math/tools/promotion.hpp than it is to Boost.Typeof, though it is not exactly the same as promote_args either.  common_type<T1, T2>::type simply represents the result of some operation on T1 and T2, and defaults to the type obtained by putting T1 and T2 into a conditional statement.
> It is meant to be customizable (via specialization) if this default is not appropriate.  Here is a link to the D version of the same tool:

I'm replying here, but thank you, Vicente, for your explanation as
well. I'm trying to figure out what the best tool for the job is and
it appears I have 3 choices, Typeof, common_type, and promote_args.
Suppose I have a mixed type vector2 class with a magnitude_squared
function defined as:

template <typename X, typename Y>
BOOST_TYPEOF_TPL(X() * X() + Y() * Y()) magnitude_squared(const
vector2<X, Y> &v) {
   return v.x * v.x + v.y * v.y;

Typeof works, but I'm wondering if it's overkill and that perhaps
common_type is much more lightweight and appropriate. promote_args
doesn't do quite what I need here, but thank you for pointing that
facility out to me.

Regardless, the original post was about how to proceed, and I
definitely see reason to break those components out of Boost.Chrono.
I didn't mean to hijack the thread ;)

--Michael Fawcett

Boost list run by bdawes at, gregod at, cpdaniel at, john at