[fpc-pascal] Class Operators

Andreas Schneider aksdb at gmx.de
Fri Dec 11 18:51:53 CET 2009


since my reported "bug" (http://bugs.freepascal.org/view.php?id=15315) seems 
to turn out to be "by design", a question came up:
are there any plans to implement class operators? In delphi they are 
implemented to allow operators to affect instances of classes. This would also 
enable to write operator overloads that work with generics. A good example of 
that would be smartpointers. A small snippet from an example in delphi:

  TSmartPointer<T: class> = record
  strict private
    FValue: T;
    FLifetime: IInterface;
    constructor Create(const AValue: T); overload;
    class operator Implicit(const AValue: T): TSmartPointer<T>;
    property Value: T read FValue;

There are surely other cases where class operators would fit in nice. They 
could for example allow to build something like TPersistent.Assign as := 

Is this already on a todo-list or am I out of luck here?


More information about the fpc-pascal mailing list