>
> 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
conversion as the underlying types are the same. I just have no idea how.

On Sun, 16 Jul 2023 at 19:59, Kurtis Rader <kra...@skepticism.us> wrote:

> 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 preferable.
>
> On Sun, Jul 16, 2023 at 9:02 AM 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)
>>
>> --
>> 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/3051ef4c-718b-4bbd-bac4-b0bf9a414283n%40googlegroups.com
>> <https://groups.google.com/d/msgid/golang-nuts/3051ef4c-718b-4bbd-bac4-b0bf9a414283n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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/CAGdsN_rpRzOtokpA%3Dd75Xg8v41D4%3DOQuU8dC2fL3fUbL7Vv%3D7w%40mail.gmail.com.

Reply via email to