On Sun, Jul 16, 2023 at 6:02 PM Leonard Mittmann <leonard.mittm...@gmail.com> 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 = (map[uintXXX]uintXXX)(m) Yes, AFAICT, the language specification does not allow such conversion. The underlying types of uintXXX and uint are the same, so a conversion between uintXXX and uint is allowed in certain situations. However, the underlying types of map[uintXXX]uintXXX and map[uint]uint and are different and thus the conversion is not possible. Exact details available at https://go.dev/ref/spec#Conversions. A different question is - could the specs allow this particular conversion? I guess probably yes. If you can think of a backwards compatible specs change that relaxes the conversion rules and allows this and does not have any bad side effects, it might be a good idea to fill a proposal at the issue tracker. It will be considered, if not already rejected before. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA40n-Wit7zW7QUDNJR%2BrujhokRxJ0e74xRFTGXX%2BtoNspVB8Q%40mail.gmail.com.