How to expand an expression along with a parameter tuple?
TommiT
tommitissari at hotmail.com
Mon Jun 17 18:51:27 PDT 2013
On Monday, 17 June 2013 at 13:59:34 UTC, Artur Skawina wrote:
>
> Another solution would be to have the following hidden in some
> lib:
>
> struct _ForEach(alias MAP, TS...) {
> NTup!(TS.length, typeof(MAP(TS[0].init))) tuple;
>
> this(TS values) {
> foreach (i, ref v; values)
> tuple[i] = MAP(v);
> }
> }
>
> auto ForEach(alias MAP, TS...)(TS ts) {
> return _ForEach!(MAP, TS)(ts);
> }
>
> Then 'bar' becomes just:
>
> void bar(T...)(T values) {
> foo(ForEach!(a=>arr[a]*10)(values).tuple);
> }
>
> Yes, this is not as concise as '...' would be. But, with a bit
> more
> tuple support in the language, the '.tuple' part wouldn't be
> necessary, and then it's just
>
> foo(ForEach!(a=>arr[a]*10)(values));
> vs
> foo((arr[values] * 10)...);
>
> artur
Now, this is pretty cool. But I wonder a couple of things:
1) What kind of an impact does this have on compilation times
compared to having this new ellipsis syntax which would allow the
compiler to do a simple rewrite.
2) I wonder if the compiler can optimize that _ForEach struct
away.
More information about the Digitalmars-d-learn
mailing list