[fpc-pascal] Primitive Record Wrappers
mazofeifer at gmail.com
Tue Mar 1 04:08:00 CET 2016
2016-02-29 13:16 GMT-03:00 Sven Barth <pascaldragon at googlemail.com>:
> Am 29.02.2016 16:13 schrieb "Mazola Winstrol" <mazofeifer at gmail.com>:
> > I have noticed that, by using generics, we can't overload arithmetic
> > E.g.:
> > ...
> > class operator Negative(A: TNullableType<T>): T;
> > ...
> > class operator TNullableType<T>.Negative(A: TNullableType<T>): T;
> > begin
> > Result := -1 * A;
> > end;
> > ....
> > wouldn't compile with the error "Operator not applicable to this operand
> > Is there any workaround to overcome this?
> As far as I am concerned that *should* work. If it does not, then it's a
> bug. Please file a bug report with a simple example program.
I apologize, it works.
There is a problem in my design. The code won't compile if i try to
specialize with a type which doesn'y supports arithmetic operators e.g
==== code ====
TNullableType<T> = record
class operator Negative(A: TNullableType<T>): T;
TString = TNullableType<String>;
class operator TNullableType<T>.Negative(A: TNullableType<T>): T;
Result := -1 * A.FValue;
=== code ====
Compilation error: "Operator is not overloaded: "ShortInt" * "AnsiString" ";
Is there any way to overcome this? Is there any way to tell the compiler to
ignore some operators depending on the specialization type?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal