Some examples beyond that overused "list of things" example.

Some examples beyond that overused "list of things" example.
http://delphisorcery.blogspot.com/2014/10/the-real-power-of-generics.html

Comments

  1. Here's something I toyed with, to avoid the overhead of the RTTI invoke method. Essentially reduces overhead to two virtual calls per invokation.


    var
      widget: TWidget;
      f: RIFunc; // reference to function(const Instance): string;
      name: string;
    begin
      widget := ...
      f := RI.PropGetter('Name');
      name := f(widget);
      WriteLn(name);
    end;

    Can do regular methods too of course.

    Anyway yea generics can be useful for more than containers :-)

    ReplyDelete
  2. Generics are great for aggregation too.

    ReplyDelete

Post a Comment