Parameter pack expansion
Q. Schroll
qs.il.paperinik at gmail.com
Thu May 30 20:55:00 UTC 2019
On Thursday, 30 May 2019 at 20:20:47 UTC, Tomas wrote:
> I'm very new to D, coming from C++ I'm missing parameter pack
> expansion and fold expressions.
I also miss the expansion operator and fold expressions.
In D, there is no such thing, and simulating it in a general way
has so much friction, I just used string mixin to solve these.
I even thought about writing a DIP, but I think, it wouldn't make
it.
In my static indexing DIP [1], there is a suggestion to add an
expansion operator, but that would only work on sequences and
similar things.
If it would be implemented, you could place your parameter pack
into a Tuple-like structure with an opDispatch that returns such
a Tuple again, but the contents would be the member components
"projection" to the member. It's doable[2], but the lack of
indexing the pack is the main blocker.
If you look closer, the DIP proposes to make "pack..." work by
replacing it with pack[0], ..., pack[$ - 1] if the indexing and
length are there to do it.
The DIP doesn't give you parameter or type packs, it gives you
what you need to implement them; still, fold expressions are
still not possible. They are rather easy to implement using D's
template mechanisms and/or string mixin mechanisms. The
projections to the members in [2] are an example of a fold
expression.
[1] https://github.com/dlang/DIPs/pull/155
[2] https://run.dlang.io/is/tIxmQS
More information about the Digitalmars-d-learn
mailing list