This repository has been archived on 2024-06-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
coffee.pygments/tests/examplefiles/go/generics.go
Shengyu Zhang cc73886200
Add 1.18 generics support for go lexer (#2167)
- Add new predeclared identifiers: `any` and `comparable`
- Add new operator for type parameters: `~` and `|`

Ref: https://go.dev/ref/spec
2022-06-25 17:16:52 +02:00

21 lines
258 B
Go

package generics
type Int interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}
func Abs[T Int](v T) T {
if v < 0 {
return -v
} else {
return v
}
}
func Equal[T comparable](a, b T) bool {
return a == b
}
func PtrOf[T any](v T) *T {
return &v
}