Нет описания

123456789101112131415161718192021222324252627
  1. package main
  2. // COMPARABLE EXAMPLE OMIT
  3. // Index returns the index of x in s, or -1 if not found.
  4. func Index[T comparable](s []T, x T) int {
  5. for i, v := range s {
  6. // v and x are type T, which has the comparable
  7. // constraint, so we can use == here.
  8. if v == x {
  9. return i
  10. }
  11. }
  12. return -1
  13. }
  14. // COMPARABLE EXAMPLE OMIT
  15. // ComparableHasher OMIT
  16. // ComparableHasher is a type constraint that matches all
  17. // comparable types with a Hash method.
  18. type ComparableHasher interface {
  19. comparable
  20. Hash() uintptr
  21. }
  22. // ComparableHasher OMIT