|
Boost : |
Subject: Re: [boost] [conversion] review
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2011-09-02 12:14:09
Stewart, Robert wrote:
> Joshua Juran wrote:
>> On Aug 29, 2011, at 3:09 PM, Phil Endecott wrote:
>> > Gordon Woodhull wrote:
>> >> If I had to write a conversion function, I would rather
>> >> write it as an overload of a general-purpose converter,
>> >> rather than giving it some ugly typeA2TypeB name.
>> >
>> > Why is e.g. rgb_to_cmyk() "ugly"?
>>
>> cmyk_t cmyk = rgb_to_cmyk( rgb );
>>
>> That's why. Compare:
>>
>> cmyk_t cmyk = cmyk_from_rgb( rgb );
>
> I prefer this:
>
> cmyk_t cmyk = to_cmyk(rgb);
>
> That permits reusing "to_cmyk" for various types via overloading.
The problem with that is the (common?) case where rgb_t is a typedef
for e.g. uint8_t[3]. This applies to other conversions too, e.g.
time_t is a typedef for int, centigrade_t and farrenheit_t are both
typedefs for float, etc. etc.
Regards, Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk