You can use type Comparable[T any] interface { Cmp(other T) int }
then *big.Int implements `Comparable[*big.Int]` and you can write func cmpSort[T Comparable[T]](x []C) { … } On Sun, Apr 10, 2022 at 7:48 PM Shawn Smith <sycomon...@gmail.com> wrote: > // ... imagine some comparison sort algorithm > > func cmpSort[C Cmpable](x []C) { > for i, val := range x { > if i == 0 { > continue > } > _ = val.Cmp(x[i-1]) > } > } > > // Cmpable should include big.Int, big.Float, big.Rat, by virtue of their > Cmp methods. So how do i define this better? > > type Cmpable interface { > Cmp(other any) int > } > // TODO: how do i replace "any" with "this type". "Cmpable" doesn't work > as that would be any Cmpable, not THIS Cmpable. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/4f167deb-bf63-43db-9ec9-c4c451c14d09n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/4f167deb-bf63-43db-9ec9-c4c451c14d09n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfFCEkYasOXPu6WNzerHKbJsDeVRfnccL0GzeXX36P_SFw%40mail.gmail.com.