[fpc-devel] New feature discussion: for-in loop

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Oct 20 11:45:50 CEST 2009


On 20/10/2009, Paul Ishenin <ip at kmiac.ru> wrote:
>
>  I don't like non-constructive criticism. If you don't like something please
> be ready to suggest something instead. And in this case something what can


By no means to I suggest that my code should be the final product, but
here I am attaching what I wrote for the Iterator article I previously
mentioned.

Please read the accompanied article as to why I did what I did. Due to
the iterators not being part of the internal list classes and because
I did not what to create descendant list classes for everything, I
followed the following approach.

I have used a Factory method to determine which Iterator should be
returned, based on the class type in question. I have also not
implement all suggested iterator interface methods - only a select few
are currently implement. I also followed the Java iterator principle
(different from Microsoft's idea) that the iterator pointer points
between elements and NOT at elements. This make a lot more sense to me
when you start the iteration (currently pointing at nothing because
the list could be empty) and when you do things like inserting
elements.

Please see attached code.

Note:
If iterators get integrated with all list classes, then the factor
method could disappear and a few other stuff could be simplified.

-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iterator_source.tar.gz
Type: application/x-gzip
Size: 2903 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20091020/63391c98/attachment.bin>


More information about the fpc-devel mailing list