-
Notifications
You must be signed in to change notification settings - Fork 1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Generic constraint where T : readonly struct
#1620
Comments
@AustinBryan How would this interact with existing compilers and runtimes? |
Maybe you can omit the 'struct' keyword from the constraint and only write 'readonly'.
readonly is (for now) only possible for structs. |
Is there any progress on this? What is language team's opinion? |
Just restricting to |
Could you please explain why a |
It would completely miss that information for any other type which might be mutable but only for specific methods. For example, If you are looking to avoid the defensive copies, an analyzer like ErrorProne.NET will solve the same problem, but will correctly flag all the scenarios without needing to touch the language. |
Sure, that makes perfect sense for that example. And in my example, my assumption is that avoiding the defensive copies would essentially amount to making overloads for each |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Right now, doing this doesn't work:
This would be useful because, when using
in
parameters and larger structs, there are performance impacts from using thein
parameter due to the defensive copy. This doesn't happen withreadonly
structs.Therefore, it would be useful constraint so we know, in the scope of the class or method, we can use
in
parameters and benefit from the performance gains.The text was updated successfully, but these errors were encountered: