[fpc-devel] [Suggestion] Enumeration range-check intrinsic
Ondrej Pokorny
lazarus at kluug.net
Sat Jul 6 09:01:29 CEST 2019
On 06.07.2019 02:10, Martok wrote:
> In that case, unlike what was previously said in this thread, this should simply
> work:
>
> generic function TStreamHelper.ReadEnum<T>(out aEnum: T): Boolean;
> begin
> if Read(aEnum, SizeOf(aEnum)) <> SizeOf(aEnum) then
> Exit(False)
> else begin
> Result := (Ord(aEnum) >= Ord(Low(T))) and (Ord(aEnum) <= Ord(High(T)));
> end;
> end;
Ord(aEnum) for invalid enumeration values is undefined ;)
Ondrej
More information about the fpc-devel
mailing list