Re: [go-nuts] map type conversion

2023-07-26 Thread Nigel van Keulen
Maybe my question could be of interest in this topic. I am not sure, and haven't tested if it works with maps, and I am also not sure if it is supposed to work / will work consistently. https://groups.google.com/g/golang-nuts/c/0RqzD2jNADE/m/3Hf14DllBAAJ?utm_medium=email_source=footer Op

Re: [go-nuts] map type conversion

2023-07-18 Thread 'Jakob Borg' via golang-nuts
On 17 Jul 2023, at 14:50, Leonard Mittmann wrote: Yes, but my thought was that it might be possible to do an unsafe conversion as the underlying types are the same. I just have no idea how. https://go.dev/play/p/ViLnLvInv-1 The unsafe conversion appears to work, but it’s unsafe and not

Re: [go-nuts] map type conversion

2023-07-17 Thread Leonard Mittmann
> > It does work (i.e., compiles) if you use a type alias (note the equal sign) > I can't use a type alias as I need a custom MarshalText-method. Yes, AFAICT, the language specification does not allow such > conversion. > Yes, but my thought was that it might be possible to do an unsafe

Re: [go-nuts] map type conversion

2023-07-16 Thread Kurtis Rader
It does work (i.e., compiles) if you use a type alias (note the equal sign): type uintXXX = uint Whether it is a good idea to allow it to work using two distinct types that have the same underlying type is debatable. Personally, I think the current behavior (not allowing the conversion) is

Re: [go-nuts] map type conversion

2023-07-16 Thread Jan Mercl
On Sun, Jul 16, 2023 at 6:02 PM Leonard Mittmann wrote: > Hi everyone, I am wondering if there is efficient way to do the following > type conversion (without looping over the map): > > var m = map[uint]uint{ /*...*/ } > type uintXXX uint > // this does not work > var m2 map[uintXXX]uintXXX =

[go-nuts] map type conversion

2023-07-16 Thread Leonard Mittmann
Hi everyone, I am wondering if there is efficient way to do the following type conversion (without looping over the map): var m = map[uint]uint{ /*...*/ } type uintXXX uint // this does not work var m2 map[uintXXX]uintXXX = (map[uintXXX]uintXXX)(m) -- You received this message because you are