I dun a DIP, possibly the best DIP ever
Adam D. Ruppe
destructionator at gmail.com
Thu May 7 14:03:24 UTC 2020
I think I just had a use for this.
I have a `const Rectangle` and wanted to shift the whole thing
down and right one unit.
Wrote:
Rectangle(r.l + 1, r.t + 1, r.b + 1, r.r + 1);
Would have been kinda cool if I could have done
Rectangle((r.tupleof + 1)...)
I don't think that can be done today since functions cannot
return tuples and templates cannot use runtime values.
Though well it perhaps could be done today with something like
auto tupleMap(alias what, T...)(T t) {
struct Ret { T pieces; }
foreach(ref arg; t)
arg = what(arg);
return Ret(t);
}
Rectangle(tupleMap!(a => a+1)(r.tupleof).tupleof);
I think that'd work and it isn't recursive template instantiation
but it is a bit wordy.
I think this new static map thing could be useful for runtime
values as well as template things.
More information about the Digitalmars-d
mailing list