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.
Consider the following:
without for-in:
procedure DoSomethingWithSet(aSet: TSetOfEnum);
var
e: TEnum;
begin
for e := Low(TEnum) to High(TEnum) do
if e in aSet then
// do something
end;
with for-in:
procedure DoSomethingWithSet(aSet: TSetOfEnum);
var
e: TEnum;
begin
for e in aSet do
// do something
end;
The second one is a bit easier to understand.
Basically for-in is syntactic sugar (like "case of string"), nothing
more, nothing less.
Regards,
Sven
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel