github.com/searKing/golang/go@v1.2.74/exp/slices/reverse.go (about) 1 // Copyright 2022 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package slices 6 7 // Reverse reorder a slice of any ordered type in reverse order. 8 // Reverse modifies the contents of the slice s; it does not create a new slice. 9 func Reverse[S ~[]E, E any](x S) { 10 for i := 0; i < len(x)>>1; i++ { 11 t := x[i] 12 x[i] = x[len(x)-1-i] 13 x[len(x)-1-i] = t 14 } 15 }