[fpc-devel] Re: enumerators
graemeg.lists at gmail.com
Sat Nov 13 23:52:42 CET 2010
On 13 November 2010 23:32, Sven Barth wrote:
> On 13.11.2010 20:56, Hans-Peter Diettrich wrote:
>> In general, what's the benefit of using enumerators? IMO a for loop
>> executes faster on (linear) string and array types, where enumerator
>> calls occur in for-in (see also my note on the UTF-8 string example).
> I'd say they simplify the code. They might not make the code faster (or even
> make it slower), but they make it easier to read/understand.
I never saw the first post, but I'll reply from here..
If you use full-blown Iterator classes (instead of just for-in style)
you get a lot more too:
* full control over iteration
- move forward
- move back
- reset iteration
- peek forward/back
- skip, etc...
* you can extent it with regular expressions to only iterate what is
applicable, and what
matches the regex.
* you completely hide the container implementation (TList,
TObjectList, TFPList, etc)
and simply supply the developer with a consistent iteration
interface. So even if the
container implementation changes, the higher level iteration code will not.
I have implemented such Iterator classes for all the most used
container classes in the RTL, and they work a treat!
- Graeme -
fpGUI - a cross-platform Free Pascal GUI toolkit
More information about the fpc-devel