[fpc-pascal] Option type

Виктор Матузенко vitek03 at gmail.com
Tue Jun 1 22:25:00 CEST 2021


Why `case`? You can make the same with a plain record:

type
  generic TOption<T> = record
    IsSome: boolean;
    some: T;
  end;

вт, 1 июн. 2021 г. в 21:26, denisgolovan via fpc-pascal <
fpc-pascal at lists.freepascal.org>:

> Hi all
>
> I am trying to implement Option<T> type in FPC.
>
> type
>   generic TOption<T> = record
>     case IsSome:boolean of
>     true: ( some: T );
>     false: ();
>   end;
>
> However fpc just emits errors:
> Error: Type parameters may require initialization/finalization - cannot be
> used in variant records
>
> Could anybody suggest some sane workaround for the problem?
>
> -- Regards,
> Denis Golovan
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>


-- 
Victor Matuzenko (Виктор Матузенко)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210601/73fdda57/attachment.htm>


More information about the fpc-pascal mailing list