It has happened a few times in the past that I have generics that are constrained to only have interfaces as generic...

It has happened a few times in the past that I have generics that are constrained to only have interfaces as generic type parameters but only work when the interface type has a guid. Constraining on interfaces works but not on having a guid (I usually solve that by checking that at runtime and throw an exception with an appropriate message).

However wouldn't it be so much nicer if I just could not compile such code because I can apply an additional constraint?

https://quality.embarcadero.com/browse/RSP-15549

Now imagine if generics would also work for standalone routines and we could have a fully type-safe version of Supports that would look like this (yes, I know you can put that into a class or record to make it work):

function Supports(const instance: IInterface; out intf: T): Boolean;

Comments