3 // Copyright 2022 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
23 type CloningMap[K comparable, V any] struct {
27 func (cm CloningMap[K, V]) With(key K, value V) CloningMap[K, V] {
28 result := CloneBad(cm.inner)
30 return CloningMap[K, V]{result}
33 func CloneBad[M ~map[K]V, K comparable, V any](m M) M {
45 m := CloningMap[string, I]{inner: make(map[string]I)}
49 it, found := m.inner["a"]
53 if _, ok := it.(*S); !ok {
54 panic(fmt.Sprintf("got %T want *main.S", it))