Paul Ishenin pisze:
Marc Weustink wrote:
I can see a use for using iterators in a for loop, however they
should be declared with some keyword.
Something like
type
TListIterator = iterator(TList, init_func, next_func, check_func)
function init_func: Boolean;
function next_func: <element type>
function check_func: Boolean;
end;
begin
for element in list using TListIterator do...
IMO this is more pascal than using some interface or predefined
function names.
Good idea. What is iterator internally? Is this an object with the
special header?
Is it internall the same as:
TListIterator = object
function init_func(AList: TList): Boolean;
function next_func: Pointer;
function check_func: Boolean;
end;
But where is current state of iterator.
next_func need to know old state and then easy move to next, but were
state is saved.
second solution receive old result, find it in collection, decode past
state and compute next, but it hurt performance
--
Darek
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel