std.array suggestion

Sean Kelly sean at f4.ca
Thu Mar 9 13:28:02 PST 2006


Kevin Bealer wrote:
> 
> Also note:  I deliberately use T1 instead of T1[] here.  I think the container
> should not be restrained to a regular array.  This code (template syntax
> omitted):
> 
> : void sum(T1 inp, T2 outp)
> : {
> :     foreach(auto sub; inp) {
> :         outp += sub;
> :     }
> : }
> 
> . is more flexible than:
> 
> : void sum(T1[] inp, T2 outp)
> : {
> :     foreach(T1 sub; inp) {
> :         outp += sub;
> :     }
> : }
> 
> Because it works with any class that can do opApply(), not just a vanilla array.

I agree.  However, opApply ranges don't support random access, so I 
think there's value in providing an array-specific overload.  find() is 
a good example here, as the opApply version would need to accept a 
delegate(size_t,inout T) and fewer optimizations would be possible.


Sean



More information about the Digitalmars-d mailing list