package main
import (
"fmt"
"sort"
)
type command struct {
name string
}
type byName [4]command
func (a *byName) Len() int { return len(*a) }
func (a *byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a *byName) Less(i, j int) bool { return a[i].name < a[j].name }
func main() {
c := byName([...]command{
{"breakpoint"},
{"help"},
{"args"},
{"continue"},
})
fmt.Println("Before sorting: ", c)
sort.Sort(&c)
fmt.Println("After sorting: ", c)
}
func main() {
c := [...]command{
{"breakpoint"},
{"help"},
{"args"},
{"continue"},
}
fmt.Println("Before sorting: ", c)
sort.Sort(&(byName(c)))
fmt.Println("After sorting: ", c)
}
src\Hello.go:26: cannot take the address of byName(c)
c := byName([...]command{{"breakpoint"},
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/SI5s9JlQBp8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The sort package has no idea whether the backing structure is slice, or array, or real goods wagons