Added == and != operators to ValueTuple.cs. Closes #10416#10417
Added == and != operators to ValueTuple.cs. Closes #10416#10417OzieGamma wants to merge 1 commit intodotnet:masterfrom
Conversation
|
Thanks @OzieGamma for the PR! @stephentoub @terrajobst The change looks good to me. I'll let you comment on public API question. FYI for @KevinRansom @gafter @VSadov |
|
I don't think we (you ?) can add == and != to This compiles fine: Tuple<string> a = new Tuple<string>("");
Tuple<string> b = new Tuple<string>("");
if (a == b)
{
}On the other hand, as mentioned above, users will potentially use ValueTuple a LOT. Not having == or != might be frustrating ... NB: I haven't played around with the new language features yet. I don't know in practice how likely I will need/want |
|
@OzieGamma You're right about backward compatibility issue on |
|
I have two main concerns with adding operator== and operator!= to System.ValueTuple. Both of them boil down to the assertion that these operators should act as if operating using == on the underlying elements. But you can’t program that into the ValueTuple type, because the implementation of the generic type doesn’t know what operator== to apply to the elements. For example
In short, I believe that adding support for operator== and operator!= to the sources of the ValueTuple libraries would be locking us in to the wrong semantics for what we would want the behavior to be. |
|
@gafter Your points make complete sense. I'll propose this on the Roslyn repo then. |
|
I |
I know I am not supposed to send a PR to master with public API changes but I could not find ValueTuple.cs and felt like this would be a good opportunity to help the .NET OSS effort !
Related issue: https://github.com/dotnet/corefx/issues/10416