I've tried to implement a generic Set
in go 1.18. I've used a map from the generic type to bool
to implement it. this requires me to add the builtin constraint comparable
to the type parameter:
type Set[T comparable] struct {
values map[T]bool
}
When I try to create a set of reflect.Type
the following error is raised:
"reflect.Type does not implement comparable"
.
I would understand this error, since reflect.Type
is an interface; However, I know that using reflect.Type
as the key of a map is explicitly allowed.
Is there any way to get around this problem other than changing the implementation of the set?