That test is only sufficient if the zeroth elements in the two slices
are at the same address, which is often not true:
https://play.golang.org/p/TH53Pxt5Do
Two slices sharing an array will, however, share their last element.
Here is a better test, but this is pretty magical stuff:
https://play.golang.org/p/SZgpCh9D-l Note that it cannot tell whether
the elements actually overlap, but you can do that too if you work a
little harder - again, capacity is the key. I leave that as an
exercise.
All that aside, copying a slice to itself is not a no-op
computationally (it will execute the copy) but the slice will not be
modified.
-rob
> --
> 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...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.