最近发布的主题
最近发布的文章
暂无
最近分享的资源
暂无
最近发布的项目
暂无
最近的评论
-
我是打开代码看到 `Elem`, 在刷新就没了,就是这么巧。我以为我眼花了。
-
#1楼 @zzustu `golang.org/x/exp/slices`包中已有切片泛型相关函数。 "代码中对泛型的声明太冗长了" ,对于这个问题最初其实很自然也是想用 E,R 等缩写。但是直到我看到 `golang.org/x/exp/slices` 包中的一些方法:https://github.com/golang/exp/blob/master/slices/sort.go 没使用缩写。 `golang.org/x/exp/slices` 片段代码 ```go // Sort sorts a slice of any ordered type in ascending order. func Sort[Elem constraints.Ordered](x []Elem) { n := len(x) quickSortOrdered(x, 0, n, maxDepth(n)) } // Sort sorts the slice x in ascending order as determined by the less function. // This sort is not guaranteed to be stable. func SortFunc[Elem any](x []Elem, less func(a, b Elem) bool) { n := len(x) quickSortLessFunc(x, 0, n, maxDepth(n), less) } ```