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.
If they wanted what you say, they would write what you say today.
The point of tuple expansions as opposed to using an array is almost certainly because you DO have mixed types.
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.