How to expand an expression along with a parameter tuple?
Artur Skawina
art.08.09 at gmail.com
Mon Jun 17 13:34:25 PDT 2013
On 06/17/13 16:20, bearophile wrote:
> Artur Skawina:
>
>> 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,
>
> Implicit things are dangerous in languages.
Not sure what you mean.
"A bit more tuple support" means aot being able to return
/real/ tuples from functions. This just needs to be specced;
can be handled like I did in the ForEach example - by wrapping
it in a struct, only internally. Then this becomes possible:
auto ForEach(alias MAP, TS...)(TS ts) {
NTup!(TS.length, typeof(MAP(TS[0].init))) tuple;
foreach (i, ref v; values)
tuple[i] = MAP(v);
return tuple;
}
void bar(T...)(T values) {
foo(ForEach!(a=>arr[a]*10)(values));
}
which is already much more readable. And 100% explicit.
While /it's only syntax sugar/, it does remove a lot of noise.
> ".tuple" can also be written "[]".
No idea what you mean by this.
artur
More information about the Digitalmars-d-learn
mailing list