Call a function on an entire slice

2012-08-29 Thread monarch_dodra
D provides ways to operate on an entire (sub) slice: int[] a = ... ; a[] *= 5; //Multiply everything by 5. a[0 .. 2] = 3; //Set indexes 0 to 1 to the value 3. I was wondering if there was any way to do this for a specified function? struct S { void foo() { writeln("foo");

Re: Call a function on an entire slice

2012-08-29 Thread Timon Gehr
On 08/29/2012 03:38 PM, monarch_dodra wrote: D provides ways to operate on an entire (sub) slice: int[] a = ... ; a[] *= 5; //Multiply everything by 5. a[0 .. 2] = 3; //Set indexes 0 to 1 to the value 3. I was wondering if there was any way to do this for a specified function? struct S {

Re: Call a function on an entire slice

2012-09-01 Thread ixid
Because the built-in arithmetic vector operators are supported by hardware. Should that matter from a user's point of view? It's a clean syntax that should be made more univeral. It'd be nice to be able to do things like: return a[] + b[]; and using that in lambdas as well without needing t