mirror of https://github.com/tinygo-org/tinygo.git
wasmstm32webassemblymicrocontrollerarmavrspiwasiadafruitarduinocircuitplayground-expressgpioi2cllvmmicrobitnrf51nrf52nrf52840samd21tinygo
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
389 B
30 lines
389 B
package main
|
|
|
|
import "unsafe"
|
|
|
|
type Coord interface {
|
|
int | float32
|
|
}
|
|
|
|
type Point[T Coord] struct {
|
|
X, Y T
|
|
}
|
|
|
|
func Add[T Coord](a, b Point[T]) Point[T] {
|
|
checkSize(unsafe.Alignof(a))
|
|
checkSize(unsafe.Sizeof(a))
|
|
return Point[T]{
|
|
X: a.X + b.X,
|
|
Y: a.Y + b.Y,
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
var af, bf Point[float32]
|
|
Add(af, bf)
|
|
|
|
var ai, bi Point[int]
|
|
Add(ai, bi)
|
|
}
|
|
|
|
func checkSize(uintptr)
|
|
|