Skip to content
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

Support compare functions with SortSlices and SortMaps #367

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

dsnet
Copy link
Collaborator

@dsnet dsnet commented Oct 23, 2024

The SortSlices and SortMaps options predate generics and
accept an interface{}, so it is possible with reflection to support other function signatures than "func(T, T) bool".

In particular, the Go ecosystem is increasingly moving towards "func(T, T) int" as the signature for ordering as evidenced by the newer slices.SortFunc function in stdlib.

Thus, modernize cmpopts by supporting "func(T, T) int".

Fixes #365

@dsnet dsnet requested a review from neild October 23, 2024 16:32
@dsnet dsnet force-pushed the dsnet/sort-compare branch from 010dae0 to 60b30aa Compare October 23, 2024 16:34
The SortSlices and SortMaps options predate generics and
accept an interface{}, so it is possible with reflection
to support other function signatures than "func(T, T) bool".

In particular, the Go ecosystem is increasingly moving towards
"func(T, T) int" as the signature for ordering as evidenced
by the newer slices.SortFunc function in stdlib.

Thus, modernize cmpopts by supporting "func(T, T) int".

Also, bump the minimum version to Go 1.21 to match
the minimum supported version of google.golang.org/protobuf.

Fixes #365
@dsnet dsnet force-pushed the dsnet/sort-compare branch from 60b30aa to d53b1ba Compare October 23, 2024 16:36
@@ -1,3 +1,3 @@
module github.com/google/go-cmp

go 1.13
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. From 4 years ago!

@dsnet
Copy link
Collaborator Author

dsnet commented Oct 23, 2024

CI are hosed and I don't have permissions to fix them, so you may need to merge on my behalf.

@neild neild merged commit 391980c into master Oct 23, 2024
7 checks passed
@dsnet dsnet deleted the dsnet/sort-compare branch October 23, 2024 16:55
@dsnet
Copy link
Collaborator Author

dsnet commented Oct 23, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cmpopts: SortSlice s and SortMaps should accept func(T,T) int signature
2 participants