Re: [fpc-devel] objfpc generics how to generate self type reference ?
Op 2019-09-03 om 13:11 schreef Mattias Gaertner via fpc-devel: Inside the generic the templates are normal types: TIteratorType = specialize THashmapIterator; Btw, mode objfpc allows shortcut THashmapIterator without <> as shortcut for "specialize THashmapIterator"; It works, thanks. I'm sure I tried it, but probably some editing mishap obscured the result. This is better than reworking to nested classes because it is backwards compat. (though gvector does use nested class as iterator) ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] objfpc generics how to generate self type reference ?
On Tue, 3 Sep 2019 12:38:49 +0200 Mattias Gaertner via fpc-devel wrote: > On Tue, 3 Sep 2019 12:15:50 +0200 > Marco van de Voort wrote: > > > I'm trying to let an iterator implement the enumerator pattern and > > return itself, but for that I need to use the type of the generic: > > > > generic THashmapIterator=class > > public > > type PValue=^TValue; > > > > // make type alias > > > > TIteratorType = generic THashmapIterator > TValue, T, TTable>; > > Inside the generic the templates are normal types: > > TIteratorType = specialize THashmapIterator TTable>; Btw, mode objfpc allows shortcut THashmapIterator without <> as shortcut for "specialize THashmapIterator"; Mattias ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] objfpc generics how to generate self type reference ?
On Tue, 3 Sep 2019 12:15:50 +0200 Marco van de Voort wrote: > I'm trying to let an iterator implement the enumerator pattern and > return itself, but for that I need to use the type of the generic: > > generic THashmapIterator=class > public > type PValue=^TValue; > > // make type alias > > TIteratorType = generic THashmapIterator TValue, T, TTable>; Inside the generic the templates are normal types: TIteratorType = specialize THashmapIterator; > > var > Fh,Fp:SizeUInt; > FData:TTable; > function Next:boolean;inline; > function MoveNext:boolean;inline; > function Prev:boolean;inline; > function GetData:T;inline; > function GetKey:TKey;inline; > function GetValue:TValue;inline; > function GetMutable:PValue;inline; > procedure SetValue(value:TValue);inline; > function getenumerator : TIteratorType ; > property Data:T read GetData; > property Key:TKey read GetKey; > property Value:TValue read GetValue write SetValue; > property MutableValue:PValue read GetMutable; > property Current : T read GetData; > end; > No repetition of templates in mode objfpc: function THashmapIterator.getenumerator : TIteratorType ; > begin > > result:=self; > > end; > > but the I can't find a TIteratorType definition that is accepted. Can > some of the objfpc generics buffs reveal the secret how to do this? > > Do I need to nest the iterators first, like in Delphi, and if so will > ($modeswitch advancedrecords} allow this? Mattias ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel