-
Notifications
You must be signed in to change notification settings - Fork 4.7k
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Remove where T : IEquatable<T>?
constraint from MemoryExtensions methods
#75639
Comments
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsWe should consider removing this constraint. It inhibits the use of almost all of the methods for
|
SequenceEqual has the constrain: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs#L966 |
That overload does. We added this overload (which optionally accepts a comparer) which does not:
|
Also note in the API review for that overload: As an alternative to just dropping the constraint (or in addition to), we could also add new overloads of all the relevant methods, similarly without a constraint and similarly accepting an optional comparer. |
We have introduced the |
I'd be fine with the alternative if we believe we won't be able to solve those T==reference type overheads: It's more overloads / more implementation (assuming we want to keep the separate implementations to avoid the shared generics overhead in the existing methods), but it's also more flexible, enabling the algorithms to be reused even with alternate comparison logic, and it wouldn't penalize existing usage, just enable usage not currently possible. |
Just bumped into this again today. I wanted the equivalent of |
Would this potentially be a reason to push harder on |
That wouldn't really help with this particular case, since the target legitimately doesn't implement the constraint. I think we need both features. |
Seems like the best option would be to add the overloads then, given the concern around impact to shared generics (and runtimes like Mono where shared generics are all they really have) |
We should consider removing this constraint. It inhibits the use of almost all of the methods for
T
s that would otherwise functionally work fine viaEqualityComparer<T>.Default.Equals
and adds relatively little benefit. Notably SequenceEqual and CommonPrefixLength don't have the constraint, but most everything else on MemoryExtensions does.The text was updated successfully, but these errors were encountered: