3
go 泛型以后会支持特例化吗
source link: https://www.v2ex.com/t/871042
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
RT ,网上搜不到有相关计划的言论和类似的问题。。
最近有个工具库想改成泛型。发现没有特例化根本写不出来。连 isEmpty 这种都写不出来。(samber/lo 的 IsEmpty 只能作用于 comparable )。
其他语言泛型之所以这么花很大的原因就是特例化。。
我在想如果函数本身特例化不好实现。以后会不会方法实现类似于
func IsEmpty[T any](x T) bool {
switchtype T {
case comparable:
var zero T
return x == zero
case xxx:
其他实现,每个 case 块做到 build 隔离,
要不 如果是 uncomparable 类型,就无法构建 == 了
case YYY:
}
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK