[fpc-pascal] Changing iterator usage pattern in FCL-STL

Sven Barth pascaldragon at googlemail.com
Sun Nov 8 23:13:46 CET 2015


Am 08.11.2015 22:36 schrieb "Michael Van Canneyt" <michael at freepascal.org>:
>
>
>
> On Sun, 8 Nov 2015, Sven Barth wrote:
>
>> On 08.11.2015 19:38, leledumbo wrote:
>>>
>>> FCL-STL from the start has different iterator usage pattern compared to
>>> existing containers (say a TSQLQuery). i.e. the common pattern is:
>>>
>>> It := SomeContainer.Iterator;
>>> while not It.EOF do begin
>>>    ...
>>>    It.Next;
>>> end;
>>>
>>> instead, it uses:
>>>
>>> It := SomeContainer.Iterator;
>>> repeat
>>>    ...
>>> until not It.Next;
>>>
>>> Examining the iterator code, I can see that the latter has at least the
>>> following disadvantage:
>>> One must add additional guard before executing repeat-until to make sure
>>> that the container has at least 1 data. Otherwise, Next in until
expression
>>> will trigger EAccessViolation.
>>>
>>> I would like to change the pattern to follow existing one. However,
FCL-STL
>>> has been available for some time now that changing the pattern will
break
>>> existing code. How do you think I should proceed on this one?
>>
>>
>> I'd say don't change. In my opinion the need to restructure one's code
outweighs that disadvantage. If anything then add a for-in compatible
iterator like was done for TVector<>.
>
>
> Enumerator, you mean ?

Yes. For most standard cases these should be enough.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20151108/cbdd6f17/attachment.html>


More information about the fpc-pascal mailing list