<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Seems like it's mixed up in some way with the FPC-style enumerator operator, so the "class" version is recognized but not actually implemented currently or something.<div><br></div><div>The normal way for classes/records/objects is to implement a GetEnumerator function, anyways. Here's an expanded-on version of your example, using your generic constants feature:</div><div><br></div><div><div>program Test;</div><div><br></div><div>{$mode ObjFPC}</div><div>{$PointerMath On}</div><div>{$modeswitch AdvancedRecords}</div><div><br></div><div>type</div><div> generic TConstArray<T; const N: PtrUInt> = array[0..N] of T;</div><div><br></div><div> generic TArrayEnumerator<T; const N: PtrUInt> = record</div><div> public type </div><div> PT = ^T;</div><div> public const </div><div> HIGH_INDEX = N;</div><div> private</div><div> CurrentIndex: PtrUInt;</div><div> DataPointer: PT;</div><div> public</div><div> function GetCurrent: T; inline;</div><div> class function Create(const A: PT): TArrayEnumerator; static; inline;</div><div> function MoveNext: Boolean; inline;</div><div> property Current: T read GetCurrent;</div><div> end;</div><div><br></div><div> generic TRec<T; const N: PtrUInt> = record</div><div> public type </div><div> TRecEnumerator = specialize TArrayEnumerator<T, N>;</div><div> private</div><div> FData: specialize TConstArray<T, N>;</div><div> public</div><div> class operator Initialize(var Rec: TRec);</div><div> function GetEnumerator: TRecEnumerator; inline;</div><div> end;</div><div><br></div><div> function TArrayEnumerator.GetCurrent: T;</div><div> begin</div><div> Result := DataPointer[CurrentIndex];</div><div> end;</div><div><br></div><div> class function TArrayEnumerator.Create(const A: PT): TArrayEnumerator;</div><div> begin</div><div> with Result do begin</div><div> DataPointer := A;</div><div> CurrentIndex := -1;</div><div> end;</div><div> end;</div><div><br></div><div> function TArrayEnumerator.MoveNext: Boolean;</div><div> begin</div><div> Inc(CurrentIndex);</div><div> Result := CurrentIndex <= HIGH_INDEX;</div><div> end;</div><div><br></div><div> class operator TRec.Initialize(var Rec: TRec);</div><div> var I: PtrUInt;</div><div> begin</div><div> for I := 0 to N do Rec.FData[I] := I;</div><div> end;</div><div><br></div><div> function TRec.GetEnumerator: TRecEnumerator;</div><div> begin</div><div> Result := TRecEnumerator.Create(@FData);</div><div> end;</div><div><br></div><div>var</div><div> Arr: specialize TRec<SizeInt, 5>;</div><div> Value: SizeInt;</div><div><br></div><div>begin</div><div> for Value in Arr do WriteLn(Value);</div><div>end.</div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 23, 2019 at 2:08 PM Ryan Joseph <<a href="mailto:ryan@thealchemistguild.com">ryan@thealchemistguild.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Is "class operator enumerator” supposed to work or is this a bug that it compiles but doesn’t do anything? Seems like it should work.<br>
<br>
===========================<br>
<br>
{$mode objfpc}<br>
{$modeswitch advancedrecords}<br>
<br>
program test;<br>
<br>
type<br>
TArrayEnumerator = class<br>
public type<br>
TArrayValue = integer;<br>
public<br>
function GetCurrent: TArrayValue;<br>
constructor Create(a: pointer);<br>
property Current: TArrayValue read GetCurrent;<br>
function MoveNext: Boolean;<br>
end;<br>
TRec = record<br>
class operator enumerator(a: TRec): TArrayEnumerator;<br>
end;<br>
<br>
class operator TRec.Enumerator(a: TRec): TArrayEnumerator;<br>
begin<br>
result := TArrayEnumerator.Create(@a);<br>
end;<br>
<br>
function TArrayEnumerator.GetCurrent: TArrayValue;<br>
begin<br>
end;<br>
<br>
constructor TArrayEnumerator.Create(a: pointer);<br>
begin<br>
end;<br>
<br>
function TArrayEnumerator.MoveNext: Boolean;<br>
begin <br>
end;<br>
<br>
var<br>
arr: TRec;<br>
value: integer;<br>
begin<br>
for value in arr do // <<<< ERROR: Cannot find an enumerator for the type "TRec"<br>
begin<br>
end;<br>
end.<br>
<br>
<br>
Regards,<br>
Ryan Joseph<br>
<br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a></blockquote></div>