Subject: Re: [boost] [chrono] type_traits/common_type and integer/ratio
From: Vicente Botet Escriba (vicente.botet_at_[hidden])
Date: 2009-12-01 22:20:32
Michael Fawcett wrote:
> On Mon, Nov 30, 2009 at 7:25 AM, Vicente Botet Escriba
> <vicente.botet_at_[hidden]> wrote:
>> "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>`."
> I've needed this feature many times. Can you explain the pros/cons of
> common_type against Boost.Typeof?
> --Michael Fawcett
> Unsubscribe & other changes:
Happy to hear you could find a use for this class.
Even if in a first look they sound to be close, common_type and typeof have
different purposes. You use typeof to get the type of an expression, while
you use common_type to set explicitly the type returned of a template
function. Both are complementary. For example with the preceding declaration
and the needed Typeof registrations, you can do
complex<int> ic; complex<double> id;
Surely others would give a better explanation,
-- View this message in context: http://old.nabble.com/-chrono--type_traits-common_type-and-integer-ratio-tp26555530p26601640.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk