Boost logo

Boost :

Subject: Re: [boost] [conversion] review
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2011-08-31 15:01:55


On Wed, Aug 31, 2011 at 1:11 AM, Joshua Juran <jjuran_at_[hidden]> 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 );
>
>> Is it because it is C, and C syntax is ancient history that must be purged
>> from modern C++?
>
> In the absence of parameterization in the caller (where the called function
> must be a template), a plain function has the advantage of looser coupling:
>  You only need the function prototype in scope, whereas to call a function
> template you need to have the specialization, (each of) which in turn needs
> the template declaration.  If you touch the header defining the template (or
> something else it includes), every user of every specialization needs to be
> recompiled.
>
> Then again, I'm biased, since one of the compilers I support sometimes
> refuses to inline functions when templates are involved, and larger include
> sets dramatically slow down compiling, because I/O is expensive.
>
> I agree with consistent naming, but I don't see <> and :: as inherently
> superior punctuation to _.

To be fair, function templates can be specialized without defining a
main template, and in that case you get the same amount of coupling as
when you use regular functions.

I do agree however that the call syntax should not rely on <>. One
reason is that it turns off ADL. Another reason is that sometimes an
implicit conversion to match an existing non-template overload is
preferable to instantiating a template.

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk