I dun a DIP, possibly the best DIP ever
Mafi
mafi at example.org
Thu Apr 23 15:06:51 UTC 2020
On Thursday, 23 April 2020 at 12:43:59 UTC, Simen Kjærås wrote:
> On Wednesday, 22 April 2020 at 12:04:30 UTC, Manu wrote:
>> This DIP single-handedly fixes compile-time issues in programs
>> I've written by reducing template instantiations by near-100%,
>> in particular, the expensive ones; recursive instantiations,
>> usually implementing some form of static map.
>>
>> We should have done this a long time ago.
>
> This is beautiful and awesome (syntax and all).
>
> I was wondering if there's any way to to do a cross product
> with this, like fun(Xs, Ys)... expand to fun(Xs[0], Ys[0]),
> fun(Xs[0], Ys[1]), fun(Xs[1], Ys[0]), fun(Xs[1], Ys[1]), but
> that might very well be rare enough to not warrant special
> consideration.
>
I think ...-Expressions should first expand nested
...-Expressions (or equivalently explicitly ignore nested
...-Expressions). Then the cross-product can be expressed as:
template crossHelper(F, X, Y...) {
alias crossHelper = F(X, Y)...;
}
crossHelper!(S, X, Y...)...
=> S!(X[0], Y[0]), S!(X[1], Y[0]), ..., S!(X[n-1], X[m-1])
because the nested expression Y... is expanded first resulting in
crossHelper!(S, X, Y[0]), ..., crossHelper!(S, X, Y[m-1]) which
then has the X expanded.
More information about the Digitalmars-d
mailing list