Am 01.06.2021 um 20:20 schrieb denisgolovan via fpc-pascal:
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

You simply can't use managed types in a variant clause and as T could be a managed type the compiler does not allow it.

Could anybody suggest some sane workaround for the problem?

Use Nullable.TNullable<T>.

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to