[fpc-pascal] Alternative to generic advanced records

Sven Barth pascaldragon at googlemail.com
Tue Feb 7 20:01:28 CET 2012


On 07.02.2012 19:52, Kornel Kisielewicz wrote:
> Ok, advanced records in 2.6.0 are it seems buggy as hell (with
> optimizations on), so I'm searching for an alternative. For the simple
> case objects work quite well, but for generics I have a problem.
>
> This is part of the code:
>
>    generic TGVector3<T>  = packed record
> {... types}
>    public
>      class function Create( aX : T = 0; aY : T = 0; aZ : T = 0 ) :
> TGVector3; static;
> {... functions}
>      class operator +( const A, B : TGVec3 ) : TGVector3;
> {... other operators}
>      class operator Explicit( const A : array of T ) : TGVector3;
> {... properties etc}
>    end;
>
> The generic record has a lot of utility functions and operators, and
> is used in specializations for Single, Double, Integer, Byte and one
> custom type, so rewriting it as not-generic is out of the question.
> Now, I'd really like to convert it to an object, but objects do not
> support built-in operators (or do they?). Any ideas how to circumvent
> that?

Even if objects would support operator overloads this would not solve 
your problem. The above operator overloads simply won't work with 
generics in 2.6.0. I'm working on the issue in 2.7.1, but it's not 
completely trivial. And no, a merge to 2.6.1 is - in my opinion - out of 
the question, because the changes in the implementation of generics 
between 2.6.0 and 2.7.1 are very massive (and they get more the more 
bugs I fix).

[Though this bugfix might even have a chance of being mergeable, but I 
won't make any promises that it will be the case in the end]

Regards,
Sven



More information about the fpc-pascal mailing list