[fpc-devel] Dangerous optimization in CASE..OF
Ondrej Pokorny
lazarus at kluug.net
Sat Apr 14 10:32:18 CEST 2018
On 14.04.2018 10:24, Michael Van Canneyt wrote:
> On Sat, 14 Apr 2018, Ondrej Pokorny wrote:
>
>> Effectively, you should be able to use:
>> var
>> E: TMyEnum;
>> begin
>> if TryIntToEnum(1, E) then
>>
>> instead of
>> if TryIntToEnum(TMyEnum, 1, E) then
>
> I am all for it, although I think the "as" syntax is more elegant, and
> that
> has my preference.
I am for both variants. If you want the "hard check" with exception on
error you use the "as" syntax, whereas if you want the "soft check" with
boolean result, you use TryIntToEnum.
IntToEnum could be added as an alternative to the "as" syntax for the
sake of consistency, if the demand is present.
But with my experience and knowledge of the compiler, the TryIntToEnum
variant will be harder to implement for me. I am a little bit struggling
with it.
Ondrej
More information about the fpc-devel
mailing list