Just wanted to say, I've been playing around with Ryan's github branch that contains this functionality and I'm loving it! It really opens up a ton of interesting possibilities in general, and also a lot of potential for optimization via constant folding for generic containers that wasn't really possible previously. Here's a more "advanced" example I threw together of the kinds of things you can actually do with this (I'm aware the final syntax for the declarations is going to be slightly different, not that it matters really):
program Example; {$Mode ObjFPC}{$H+}{$J-} {$ModeSwitch AdvancedRecords} {$PointerMath On} type generic TStaticList<T, const L: PtrUInt, const H: PtrUInt> = record public type TStaticListEnumerator = record public type PT = ^T; strict private FFirst, FLast, FCurrent: PT; public class function Create(var List: TStaticList): TStaticListEnumerator; inline; static; function MoveNext: Boolean; inline; property Current: PT read FCurrent; end; strict private Items: array[L..H] of T; public function Low: PtrUInt; inline; function High: PtrUInt; inline; procedure Initialize; inline; function GetEnumerator: TStaticListEnumerator; inline; end; class function TStaticList.TStaticListEnumerator.Create(var List: TStaticList): TStaticListEnumerator; begin with Result do begin FFirst := @List.Items[L]; FLast := @List.Items[H]; FCurrent := FFirst - 1; end; end; function TStaticList.TStaticListEnumerator.MoveNext: Boolean; begin Inc(FCurrent); Result := (FFirst <> FLast) and (FCurrent <= FLast); end; function TStaticList.Low: PtrUInt; begin Result := L; end; function TStaticList.High: PtrUInt; begin Result := H; end; procedure TStaticList.Initialize; var I: PtrUInt; begin for I := Low() to High() do Items[I] := T(I); end; function TStaticList.GetEnumerator: TStaticListEnumerator; begin Result := TStaticListEnumerator.Create(Self); end; var AsciiList: specialize TStaticList<Char, 33, 126>; P: PChar; begin AsciiList.Initialize(); for P in AsciiList do Write(P^); end.
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal