On 4/23/2020 11:52 PM, Manu wrote:
> On Fri, Apr 24, 2020 at 4:35 PM Walter Bright via Digitalmars-d
> <digitalmars-d@puremagic.com <mailto:digitalmars-d@puremagic.com>> wrote:
>
> On 4/23/2020 10:51 PM, Manu wrote:
> > Another reason I introduce `...` is for static fold.
> > The follow-up to this DIP would make this expression work:
> >
> > `Tup + ...` -> `Tup[0] + Tup[1] + ... + Tup[$-1]`
>
> I expect static foreach can handle that. But we can dig a little deeper. D
> doesn't have a special syntax to sum the elements of an array, but it can use a
> library function to do it. The next observation is that to sum the elements
> of a
> tuple, all the tuple members need to be implicitly convertible to a single
> arithmetic type. There is a way to do that:
>
> [ Tup ]
>
>
> No, it's not necessary that they are common types. It's actually the opposite
> intent of the expression.
The only way:
1 + 'a' + 1.0 + 1L + 2.0L
can be computed is if the operands are brought to a common arithmetic type.
It doesn't make much sense to think in terms of primitive types. As I just said (but you truncated), operator overloads are almost certainly part of this equation.
I think it's more common to do a fold like this with logical operators though; `&&` appears 9 times out of 10 in my code.