How to expand an expression along with a parameter tuple?
Artur Skawina
art.08.09 at gmail.com
Mon Jun 17 04:15:06 PDT 2013
On 06/17/13 11:32, TommiT wrote:
> On Monday, 17 June 2013 at 07:20:23 UTC, Ali Çehreli wrote:
>>
>> The following does not answer the question of expanding but at least foo() receives [30, 70, 110] :)
>>
>> import std.stdio;
>> import std.algorithm;
>> import std.array;
>> import std.range;
>>
>> int[] arr = [ 1, 3, 5, 7, 11 ];
>>
>> void foo(T)(T[] values...)
>> {
>> writeln(values);
>> }
>>
>> void bar(T)(T[] values...)
>> {
>> foo(arr
>> .indexed(values)
>> .map!(a => a * 10)
>> .array);
>> }
>>
>> void main()
>> {
>> bar(1, 3, 4);
>> }
>>
>> Ali
>
> Yeah, that would work. I'd hate the overhead though.
void bar(T...)(T values) {
T tmp;
foreach (i, ref v; values)
tmp[i] = arr[v]*10;
foo(tmp);
}
artur
More information about the Digitalmars-d-learn
mailing list