github.com/AESNooper/go/src@v0.0.0-20220218095104-b56a4ab1bbbb/sort/slice_go14.go (about) 1 // Copyright 2017 The Go Authors. 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 //go:build !go1.8 6 // +build !go1.8 7 8 package sort 9 10 import "reflect" 11 12 var reflectValueOf = reflect.ValueOf 13 14 func reflectSwapper(x interface{}) func(int, int) { 15 v := reflectValueOf(x) 16 tmp := reflect.New(v.Type().Elem()).Elem() 17 return func(i, j int) { 18 a, b := v.Index(i), v.Index(j) 19 tmp.Set(a) 20 a.Set(b) 21 b.Set(tmp) 22 } 23 }