Re: strange template syntax

2010-04-11 Thread BCS
Hello Philippe, Hello, some time ago, chris (ruunhb) posted something on his Dspec project, where he used a template syntax I didn't know: void each(alias array, T : T[] = typeof(array))(void delegate(T item) dg) { foreach(T i; array) dg(i); } int[] array = [1, 2, 3, 4]; int b = 10; each!

Re: strange template syntax

2010-04-11 Thread Robert Clipsham
On 11/04/10 16:01, Robert Clipsham wrote: When using your method, you have to use: each!(array, typeof(array))((int item) {writefln("%d", item+b)}); (I believe this is a bug, dmd should be able to deduce the type here). As for the syntax, you can do this with any function in D: voi

Re: strange template syntax

2010-04-11 Thread Philippe Sigaud
On Sun, Apr 11, 2010 at 17:01, Robert Clipsham wrote: > When using your method, you have to use: > > each!(array, typeof(array))((int item) {writefln("%d", item+b)}); > > (I believe this is a bug, dmd should be able to deduce the type here). OK. I suppose I'd do: void each(alias arra

Re: strange template syntax

2010-04-11 Thread Robert Clipsham
On 11/04/10 15:48, Philippe Sigaud wrote: Hello, some time ago, chris (ruunhb) posted something on his Dspec project, where he used a template syntax I didn't know: void each(alias array, T : T[] = typeof(array))(void delegate(T item) dg) { foreach(T i; array) dg(i); } int[] array

strange template syntax

2010-04-11 Thread Philippe Sigaud
Hello, some time ago, chris (ruunhb) posted something on his Dspec project, where he used a template syntax I didn't know: void each(alias array, T : T[] = typeof(array))(void delegate(T item) dg) { foreach(T i; array) dg(i); } int[] array = [1, 2, 3, 4]; int b = 10; each!(array) =