mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-27 20:11:02 +02:00
* fixed test to reflect current ideas how generics should be used
git-svn-id: trunk@5163 -
This commit is contained in:
parent
be2b715d3c
commit
107721f760
@ -1,30 +1,30 @@
|
||||
{$mode objfpc}
|
||||
|
||||
type
|
||||
generic PListItem<_T>=^specialize TListItem<_T>;
|
||||
generic TListItem<_T>=record
|
||||
data : _T;
|
||||
next : specialize PListItem<_T>;
|
||||
end;
|
||||
|
||||
generic TList<_T>=class(TObject)
|
||||
first : specialize PListItem<_T>;
|
||||
type
|
||||
PListItem = ^TListItem;
|
||||
TListItem = record
|
||||
data : _T;
|
||||
next : PListItem;
|
||||
end;
|
||||
var
|
||||
first : PListItem;
|
||||
procedure Add(item: _T);
|
||||
end;
|
||||
|
||||
procedure TList.Add(data: _T);
|
||||
procedure TList.Add(item: _T);
|
||||
var
|
||||
newitem : specialize PListItem<_T>;
|
||||
newitem : PListItem;
|
||||
begin
|
||||
new(newitem);
|
||||
newitem.data:=data;
|
||||
newitem.next:=first;
|
||||
newitem^.data:=item;
|
||||
newitem^.next:=first;
|
||||
end;
|
||||
|
||||
type
|
||||
TMyIntList = specialize TList<integer>;
|
||||
TMyStringList = specialize TList<string>;
|
||||
|
||||
var
|
||||
ilist : TMyIntList;
|
||||
slist : TMyStringList;
|
||||
@ -35,16 +35,17 @@ begin
|
||||
ilist.Add(someInt);
|
||||
ilist.Add(someInt+1);
|
||||
writeln(ilist.first^.data);
|
||||
if ilist.data<>10 then
|
||||
if ilist.first^.data<>10 then
|
||||
halt(1);
|
||||
writeln(ilist.first^.next^.data);
|
||||
if ilist.data<>11 then
|
||||
if ilist.first^.data<>11 then
|
||||
halt(1);
|
||||
|
||||
slist := TMyStringList.Create;
|
||||
slist.Add('Test1');
|
||||
slist.Add('Test2');
|
||||
writeln(slist.data);
|
||||
if slist.data<>'Test1' then
|
||||
writeln(slist.first^.data);
|
||||
if slist.first^.data<>'Test1' then
|
||||
halt(1);
|
||||
writeln('ok');
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user