DMD 0.170 release

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue Oct 17 23:23:25 PDT 2006


Bill Baxter wrote:
> Oskar Linde wrote:
>> Tom S wrote:
>>
>> [snip proposal]
>>
> 
>> The possibilities seem endless. It is almost scary. And best of all: 
>> It doesn't contain a single template. :)
> 
> Er, but what if you want to support more than int[] as the type to be 
> looped over?
> 
>  > void each(int[] a, void delegate(int) dg, inout void* ret) {
>  >     for (int i = 0; i < a.length; ++i) {
>  >         dg(a[i]);
>  >         if (ret) return;
>  >     }
>  > }
> 
> Looks to me like you've got you an int[]-specific looper there.  Gonna 
> need some templates to make that generic, no?

Yes. For the built in arrays, you would need either templates, or do as 
phobos does internally, work with void * and TypeInfo.

The construct in itself is template less. But if you make your own 
generic container, you will of course need to make your iterator generic 
too.

The "best of all"-part was a joke. :)

/Oskar



More information about the Digitalmars-d-announce mailing list