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 // +build !go1.8 6 7 package sort 8 9 import "reflect" 10 11 var reflectValueOf = reflect.ValueOf 12 13 func reflectSwapper(x interface{}) func(int, int) { 14 v := reflectValueOf(x) 15 tmp := reflect.New(v.Type().Elem()).Elem() 16 return func(i, j int) { 17 a, b := v.Index(i), v.Index(j) 18 tmp.Set(a) 19 a.Set(b) 20 b.Set(tmp) 21 } 22 } 23