...

Source file src/cmd/compile/internal/test/testdata/ptrsort.go

Documentation: cmd/compile/internal/test/testdata

     1  package main
     2  
     3  // Test generic sort function with two different pointer types in different packages,
     4  // make sure only one instantiation is created.
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"cmd/compile/internal/test/testdata/mysort"
    10  )
    11  
    12  type MyString struct {
    13  	string
    14  }
    15  
    16  func (a *MyString) Less(b *MyString) bool {
    17  	return a.string < b.string
    18  }
    19  
    20  func main() {
    21  	mysort.F()
    22  
    23  	sl1 := []*mysort.MyInt{{7}, {1}, {4}, {6}}
    24  	mysort.Sort(sl1)
    25  	fmt.Printf("%v %v %v %v\n", sl1[0], sl1[1], sl1[2], sl1[3])
    26  
    27  	sl2 := []*MyString{{"when"}, {"in"}, {"the"}, {"course"}, {"of"}}
    28  	mysort.Sort(sl2)
    29  	fmt.Printf("%v %v %v %v %v\n", sl2[0], sl2[1], sl2[2], sl2[3], sl2[4])
    30  }
    31  

View as plain text