Can we get rid of opApply?
Max Samukha
samukha at voliacable.com.removethis
Tue Jan 20 09:32:27 PST 2009
On Tue, 20 Jan 2009 09:08:03 -0800, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
>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
I have to use an updated version of that algorithm:
1. Wake up
2. Get coffee
3. Read _all_ posts
4. Post only if necessary and think before posting
More information about the Digitalmars-d
mailing list