[fpc-devel] [Feature Request] get nested type from a generic class
Sven Barth
pascaldragon at googlemail.com
Fri Sep 21 09:49:54 CEST 2012
Am 21.09.2012 03:57, schrieb ZAN DoYe:
> I wanna make a generic class that can generates all six relational
> operators with the passed in class T which has only one lessThan
> operator. But fpc can't recognize blow code:
>
> generic tLess<T>= class
> public type
> tT= T;
> public
> class function lessThan(const a, b: T): boolean;
> end;
>
> generic tCompOps<C>= class
> public type
> T= C.tT; //// Error: Error in type
> definition ////
> public
> class function equal(const a, b: T): boolean;
> class function notEqual(const a, b: T): boolean;
> class function lessThan(const a, b: T): boolean;
> class function lessThanOrEqual(const a, b: T): boolean;
> class function greaterThan(const a, b: T): boolean;
> class function greaterThanOrEqual(const a, b: T): boolean;
> end;
>
> I hope this feature could be implemented if it's possible.
If you already expect that "C" is a "tLess<Something>" then you should
write it the following way:
=== source begin ===
// tLess<T> as in your example
generic tCompOps<T> = class
public type
TLessT = specialize tLess<T>;
public
// the remaining methods are like in your example with the
exception that in the implementation you don't use type "C", but "TLessT"
end;
=== source end ===
Regards,
Sven
More information about the fpc-devel
mailing list