[fpc-pascal] Re: Support for C++ library format?

Jorge Aldo G. de F. Junior jagfj80 at gmail.com
Fri Oct 9 02:52:21 CEST 2009


One thing that i did not like about FPC Generics is the impossibility of
doing something like this :

Type
  generic TList<_T>=class(TObject)
    type public
       TCompareFunc = function(const Item1, Item2: _T): Integer;
    var public
      data : _T;
    procedure Add(item: _T);
    procedure Sort(compare: TCompareFunc);
  end;

  generic TAdvancedList<_T>=Class(TList<_T>)
   procedure push(item: _T);
   function pop: _T;
  end;

  generic TOtherList<_T>=Class(TList<_T>)
    procedure enqueue(item: _T);
    function dequeue: _T;
  End;

I dont think i explained it very well, the idea was that you cant have
generic classes making part of the inheritance tree without specializing
then 1st. This makes generics interfere (limiting it) with object oriented
polimorphysm... having generics of generics would allow a complete STL
capable of being changed (on the fly) into anything needed... (well, i might
very well understood generics model wrongly)

one of the solutions i thought was something like this :

Type
  generic TList<_T>=class(TObject)
    type public
       TCompareFunc = function(const Item1, Item2: _T): Integer;
    var public
      data : _T;
    procedure Add(item: _T);
    procedure Sort(compare: TCompareFunc);
  end;

  generic TAdvancedList<_T2> = Class(specialize(TList<_T2>))
     procedure Push(item : _T2);
     function Pop: _T2;
  End;

When the programmer makes :

Type
    TAdvancedListByte = specializeTAdvancedList<Byte>;

the compiler would automagically generate an intermediate TListByte that
specializes TList<_T> (Replacing _T with _T2) and replace the original
Class(specialize(TList<_T2>)) with Class(TListByte), all of this on the
fly,  making intermediate classes to be part of the inheritance tree, and
allowing a big generics library possible...

thats my two cents...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20091008/795e66d6/attachment.html>


More information about the fpc-pascal mailing list