Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread Josh Humphries
On Tue, Aug 1, 2017 at 2:43 PM, roger peppe wrote: > On 1 August 2017 at 19:33, Josh Humphries wrote: > > On Tue, Aug 1, 2017 at 11:44 AM, roger peppe wrote: > >> > >> On 1 August 2017 at 13:57, Josh Humphries

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread roger peppe
On 1 August 2017 at 19:33, Josh Humphries wrote: > On Tue, Aug 1, 2017 at 11:44 AM, roger peppe wrote: >> >> On 1 August 2017 at 13:57, Josh Humphries wrote: >> > Although that solution creates a heap-allocated tmp for every

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread Josh Humphries
On Tue, Aug 1, 2017 at 11:44 AM, roger peppe wrote: > On 1 August 2017 at 13:57, Josh Humphries wrote: > > Although that solution creates a heap-allocated tmp for every element in > the > > slice. Using an interface, the value will be inlined instead

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread roger peppe
On 1 August 2017 at 13:57, Josh Humphries wrote: > Although that solution creates a heap-allocated tmp for every element in the > slice. Using an interface, the value will be inlined instead of > heap-allocated if it fits without boxing (so most primitive types and >

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread Jan Mercl
On Tue, Aug 1, 2017 at 2:58 PM Josh Humphries wrote: > Using an interface, the value will be inlined instead of heap-allocated if it fits without boxing (so most primitive types and pointer types won't need heap allocation). This was true some years ago, but it is no

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread Josh Humphries
Although that solution creates a heap-allocated tmp for every element in the slice. Using an interface, the value will be inlined instead of heap-allocated if it fits without boxing (so most primitive types and pointer types won't need heap allocation). *Josh Humphries* jh...@bluegosling.com

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-08-01 Thread roger peppe
FWIW, you don't have to use Interface to do the swap: https://play.golang.org/p/O8lGJGGOXP On 31 July 2017 at 15:18, eZio Pan wrote: > Hello, > I want to build a "universal slice reverser" with reflect.MakeFunc. But I > don't know how to get a copy of reflect.Value's

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-07-31 Thread Josh Humphries
You have to use a temporary to swap the values: tmp := a.Interface() a.Set(b) b.Set(reflect.ValueOf(tmp)) *Josh Humphries* jh...@bluegosling.com On Mon, Jul 31, 2017 at 10:18 AM, eZio Pan wrote: > Hello, > I want to build a "universal slice reverser" with

Re: [go-nuts] Get a copy of reflect.Value's underlying value

2017-07-31 Thread Jan Mercl
On Mon, Jul 31, 2017 at 4:18 PM eZio Pan wrote: > My code return [7 6 5 5 6 7], but excepting result is [7 6 5 4 3 2] https://play.golang.org/p/yraJZFDjS3 -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

[go-nuts] Get a copy of reflect.Value's underlying value

2017-07-31 Thread eZio Pan
Hello, I want to build a "universal slice reverser" with reflect.MakeFunc. But I don't know how to get a copy of reflect.Value's underlying value, which make result not correct. Here is the code: package main import ( "fmt" "reflect" ) func reverse(in []reflect.Value) (out []reflect.Value) {