Hacker News new | ask | show | jobs
by neonsunset 432 days ago
> I think I can do that in a no overhead way.

If 'T' is a struct, yup, although that's specific to the way it is compiled by CoreCLR's JIT or ILC.

For constructor semantics it's best to expose a static abstract interface method Create<T> and have the interface be SomeInterface<Self> where Self : ISomeInterface<Self>.

For example, that's how `INumber<T>` interface works so you can further down the line write `T.Zero`.

1 comments

Yep, in the current restrictions `T` has to be a struct (no heap allocations means no reference types are supported).

Huh, interesting idea with the `Self` generic dependency for the `Create<T>`. That's an interesting angle I hadn't thought of, thanks.