c-family: char8_t and aliasing in C vs C++ [PR111884]
[official-gcc.git] / libgo / go / sort / slice_go14.go
blobe4773676185bca9ea403f1cfccb338ade1bc85fa
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.
5 //go:build !go1.8
6 // +build !go1.8
8 package sort
10 import "reflect"
12 var reflectValueOf = reflect.ValueOf
14 func reflectSwapper(x any) 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)