Boost logo

Boost :

Subject: Re: [boost] Naming convention of iterated binary operation
From: Jeremy Murphy (jeremy.william.murphy_at_[hidden])
Date: 2016-05-03 01:37:22


On 3 May 2016 at 05:19, Rob Stewart <rstewart_at_[hidden]> wrote:

> On May 2, 2016 5:30:40 AM EDT, Jeremy Murphy <
> jeremy.william.murphy_at_[hidden]> wrote:
> >
> >A variadic template version with the same name makes sense to me,
> >though.
>
> There's some detail missing. How is your iterated GCD function different
> from a variadic gcd()?

Only in the type signature. It's fairly obvious but I'll make it explicit.
Variadic gcd takes n things of type T and returns a T:

f(T, ..., T) -> T

whereas "iterated" gcd takes a thing (Range) or things (iterators) that
denote a range of Ts:

g(U) -> T
g(U, U) -> T

So yes, in the implementation, variadic gcd is an iterated binary operation
(with special case of n=1).
But the semantics are different because of how the input is interpreted,
which for me is sufficient reason to give them different names.

So it's probably more accurate that I say it's gcd over an iterator range
that I think should have a different name to 'plain' gcd (which is iterated
in a variadic version).
Which makes the "_range" suffix all the more sensible.

Cheers.

Jeremy


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