Can we get rid of opApply?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jan 20 09:04:52 PST 2009


Steven Schveighoffer wrote:
> "dsimcha" wrote
>> foreach(char[] s; array) vs.
>> foreach(char[] s; IntegersAsString(array))
>>
>> I think a lot of stuff is going to need some kind of extra struct like 
>> this to
>> make it work.  When this is the case, it needs to be possible to have a 
>> default
>> iteration method that "just works."  The opDot overload, I guess, could do 
>> this,
>> but it's a rather blunt tool, since then you can't use opDot for other 
>> stuff and
>> you'd have to forward _everything_ to the opDot object.
> 
> opRange doesn't help here.  array is a (non-extendable) primitive, so the 
> compiler needs to be told how to convert integers to strings.
> 
> Even opApply wouldn't get you here.
> 
> I actually think something cool would be a toRange struct:
> 
> foreach(s; toRange!(string)(array))
> 
> Which would be like the to! template.
> 
> -Steve 

With the new std.algorithm:

foreach (s; map(to!string)(array)) { ... }


Andrei



More information about the Digitalmars-d mailing list