<div dir="ltr"><div dir="ltr">On Fri, Apr 24, 2020 at 4:35 PM Walter Bright via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 4/23/2020 10:51 PM, Manu wrote:<br>
> Another reason I introduce `...` is for static fold.<br>
> The follow-up to this DIP would make this expression work:<br>
> <br>
> `Tup + ...` -> `Tup[0] + Tup[1] + ... + Tup[$-1]`<br>
<br>
I expect static foreach can handle that. But we can dig a little deeper. D <br>
doesn't have a special syntax to sum the elements of an array, but it can use a <br>
library function to do it. The next observation is that to sum the elements of a <br>
tuple, all the tuple members need to be implicitly convertible to a single <br>
arithmetic type. There is a way to do that:<br>
<br>
[ Tup ]<br></blockquote><div><br></div><div>No, it's not necessary that they are common types. It's actually the opposite intent of the expression.</div><div>If they wanted what you say, they would write what you say today.</div><div><br></div><div>The point of tuple expansions as opposed to using an array is almost certainly because you DO have mixed types.</div><div>If the BinOp is logical, anything that can coerce to true/false is acceptable. If it's arithmetic, then operator overloads are probably part of the equation.</div><div><div></div><div></div></div></div></div>