[fpc-pascal] Generic type declaration example versus manual.
Pascal
sur.pignard at wanadoo.fr
Sat Nov 21 19:00:09 CET 2009
Hello.
In example tgeneric16.pp (from FPC 2.2.4 sources) the generic type
TStack is declared as:
type
{ TStack }
generic TStack<T> = class(TObject)
public
procedure Clear; virtual;
destructor Destroy; override;
end;
Though in FPC manual type is described as:
type declaration: identifier = type ;
type: simple type
string type
structured type
pointer type
procedural type
generic type
specialized type
type identifier
generic type: generic identifier < template list > = generic class ;
Following the manual, the type identifier is thus declared two times:
- in type declaration
- in generic type
Like:
TStack = generic TStack<T> = class(TObject)
public
procedure Clear; virtual;
destructor Destroy; override;
end;
The syntax found in the example doesn't take care of the first
identifier in type declaration.
May I suggest the following:
TStack = generic <T> class(TObject)
public
procedure Clear; virtual;
destructor Destroy; override;
end;
This syntax looks like more Pascal conformant, i.e. it doesn't brake
Pascal type declaration "identifier = type;"
And this prevent the succession of greater and equal characters in
"generic TStack<T>=class(TObject)" which may be considered as greater
or equal ">=" by the compiler.
For sure, the simpler would be to change the manual ;-)
What are your feedbacks ?
Regards, Pascal.
http://blady.pagesperso-orange.fr
More information about the fpc-pascal
mailing list