Support for mutually exclusive type constraints #8790
Replies: 3 comments
-
It's a limitation of the CLR type system. Constraints don't make up part of the signature of a type. |
Beta Was this translation helpful? Give feedback.
-
Where T struct can be achieved by deriving Pointer And is type safe but you must use class. And they why have a constraint at all on the base type? Make the base type expose a nested struct and then you have your pseduo struct inheritance You could also achieve this without derived classes at all simply using a overloaded constructor on the struct. Not sure really how useful that would be yet but it sounds like a solution to this proposal. |
Beta Was this translation helpful? Give feedback.
-
@juliusfriedman that is a bit of a hack around it, and not very nice to use. iirc, generic modreqs are a bit weird and cannot just be arbitrarily inserted into the generic signature (i tried), so without runtime changes this is a no go, but i might be wrong |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Doing some heavy metaprogramming style work I stumbled upon a limitation of the language that would be very useful now that we are starting to use type constraints for performance sensitive code.
The following code would fail with an inconsistent type parameter error.
However, in this case, the type parameters are mutually exclusive of one another. Disambiguation would allow you to write code that takes a
Pointer<T>
without any constraint and still be possible to write class/struct agnostic code.Beta Was this translation helpful? Give feedback.
All reactions