<div dir="ltr"><div dir="ltr">On Fri, Apr 24, 2020 at 5: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 11:52 PM, Manu wrote:<br>
> On Fri, Apr 24, 2020 at 4:35 PM Walter Bright via Digitalmars-d <br>
> <<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a> <mailto:<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>>> wrote:<br>
> <br>
>     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<br>
>     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>
> <br>
> <br>
> No, it's not necessary that they are common types. It's actually the opposite <br>
> intent of the expression.<br>
<br>
The only way:<br>
<br>
   1 + 'a' + 1.0 + 1L + 2.0L<br>
<br>
can be computed is if the operands are brought to a common arithmetic type.<br></blockquote><div><br></div><div>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.</div><div>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.</div></div></div>