# Boost :

Subject: Re: [boost] [ratio] Assignation between equivalent ratios
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2009-12-07 09:18:09

On Dec 7, 2009, at 6:44 AM, vicente.botet wrote:

>
> ----- Original Message -----
> From: "Howard Hinnant" <howard.hinnant_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Sunday, December 06, 2009 11:42 PM
> Subject: Re: [boost] [ratio] Assignation between equivalent ratios
>
>
>>
>> On Dec 6, 2009, at 1:33 PM, vicente.botet wrote:
>>
>>> Hi,
>>>
>>> I was wondering if we need to be able to make assignations between equivalent ratios. e.g.
>>>
>>> ratio<1,3> r1;
>>>
>>> ratio<3,9> r2;
>>>
>>> r1 = r2; // (1)
>>>
>>>
> <snip>
>>>
>>> I'm missing something? Any thougths?
>>
>> Hi Vicente,
>>
>> I think you've made a good observation. The original intent was to just have the special members of <ratio> governed by [functions.within.classes]. However your example code has given me pause for thought. I haven't found any motivating use cases for the assignment operator. But I can easily think of motivating uses for the copy constructor (and having the assignment operator be consistent, with the copy constructor, motivating cases or not, makes sense). I'm experimenting with the following special members and things look good to me:
>>
>> ratio() {}
>>
>> template <intmax_t _N2, intmax_t _D2>
>> ratio(const ratio<_N2, _D2>&,
>> typename enable_if
>> <
>> ratio<_N2, _D2>::num == num &&
>> ratio<_N2, _D2>::den == den
>>> ::type* = 0) {}
>>
>> template <intmax_t _N2, intmax_t _D2>
>> typename enable_if
>> <
>> ratio<_N2, _D2>::num == num &&
>> ratio<_N2, _D2>::den == den,
>> ratio&
>>> ::type
>> operator=(const ratio<_N2, _D2>&) {return *this;}
>>
>> I.e. ratio is default constructible, and can be constructed or assigned from any ratio which has the same normalized form.
>>
>> I encourage you to write up an issue for the LWG issues list proposing this addition. Instructions for doing so can be found here:
>>

>>
>> Thanks for working on this.
>>
> Hi,
>
> do you think it is worth considering a ratio generator that will ensure a normalized ratio. In thi way
>
> ratio_normalizer<1,3>::type will be the same as ratio_normalizer<3,9>::type. So no need to add the copy constructors and assignement operators.

If we want to do this, I suspect the easiest thing would be to make type a nested typedef of ratio itself:

ratio<3,9>::type is ratio<1,3>

-Howard