Subject: Re: [boost] [chrono] type_traits/common_type and integer/ratio
From: John Maddock (john_at_[hidden])
Date: 2009-12-01 08:24:45
> You can see [http://www.open-std.org/jtc1/sc22/wg21 [*N2661 - A Foundation
> to Sleep On]] which is very informative and provides motivation for key
> design decisions for `common_type`, ratio and chrono.
> I really think they are very useful and the standard group also, as both
> in N3000.
> Here there are some extracts
> "In a nutshell, `common_type` is a trait that takes 1 or more types, and
> returns a type which all of the types will convert to. The default
> definition demands this conversion be implicit. However the trait can be
> specialized for user-defined types which want to limit their inter-type
> conversions to explicit, and yet still want to interoperate with the
> `common_type` facility.
> template <class T, class U>
> typename common_type<complex<T>, complex<U> >::type
> operator+(complex<T>, complex<U>);
> In the above example, "mixed-mode" complex arithmetic is allowed. The
> type is described by `common_type`. For example the resulting type of
> a `complex<int>` and `complex<double>` might be a `complex<double>`."
OK, looking into that a bit more, I think that would be a reasonably
uncontrovercial addition to type_traits - but do you have a test suite and
> "`ratio` is a general purpose utility inspired by Walter Brown allowing
> to easily and safely compute rational values at compile time. The `ratio`
> class catches all errors (such as divide by zero and overflow) at compile
> time. It is used in the `duration` and `time_point` classes to efficiently
> create units of time. It can also be used in other "quantity" libraries
> (both std-defined and user-defined), or anywhere there is a rational
> constant which is known at compile time. The use of this utility can
> reduce the chances of run time overflow because the `ratio` (and any
> resulting from `ratio` arithmetic) are always reduced to lowest terms.
This one's quite a bit of an addition - almost a little mini-library in it's
I think you're correct that it should be locatable as a utility in it's own
right, and yes under boost/integer I guess. My suggestion is that you ask
for a review for ratio separately from chrono. BTW the utilities here
be useful for the implementation of this one, rather than re-inventing your
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk