[fpc-pascal] Can class function used in specialized class use intristic functions Low, High with generic type ?
Sven Barth
pascaldragon at googlemail.com
Thu Apr 20 14:37:27 CEST 2017
Am 20.04.2017 13:02 schrieb "LacaK" <lacak at zoznam.sk>:
>
> Hi *,
>
> I have some generic class:
>
> generic T2DNumericArray<T> = object(specialize T2DArray<T>)
> public
> class function Truncate(Value: double): T; inline;
> ...
>
> In class function Truncate I want check if supplied Value is in range of
T.
> T will be always ordinal type (byte, integer) ... (I know this, but
compiler does not of course)
>
> Can I use in :
>
> class function T2DNumericArray.Truncate(Value: double): T;
> begin
> if Value > High(T) then
> Result := High(T)
> else if Value < Low(T) then
> Result := Low(T)
> else
> Result := Value;
> end;
>
> I understand, that from compiler POV T can be any type, so High() and
Low() can be invalid, but I wonder if there is any way how to solve this.
The compiler will use dummy values while parsing the generic, but during
specialization it will use the correct ones. Though it might be that you'd
need 3.1.1 for it (dont know right now when I had fixed that).
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170420/06d7b655/attachment.html>
More information about the fpc-pascal
mailing list