-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
take address of field for comparison #310
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
The fact that values are not always treated as addressable is my biggest regret for the I'm sympathetic to adding a fundamental option like: // ForceAddressable treats all values as if they were addressable.
func ForceAddressable() Option but would also like to see if it could be enabled by default in a v1.0.0 release of the package. As a workaround, you can do something like: // MakeAddressable takes the address of values of T,
// so that methods or options that operate on *T become applicable.
func MakeAddressable[T any]() cmp.Option {
return cmpopts.AcyclicTransformer("Addr", func(v T) *T {
return &v
})
} and perhaps that's also something we should add to the Example usage of |
A similar problem occurs with a struct that contains a
But "go vet" (correctly) complains:
This doesn't work:
cmp then doesn't apply the transformation, leading to the original problem:
Any suggestions? |
I'm using intsets.Sparse as a field in a struct:
When traversing
T
, the fieldv
is copied, causing all methods to fail. This precludes the use ofTransformer
.Ideally, there would be an
Option
that would take the address of the field for use with otherOption
s. Notably,Sparse
has anEquals(*Sparse) bool
method, so perhaps an alternate idea is to allow different equality methods? But I'm not sure whethergo-cmp
will take the address of a field in order to invoke theEqual
method.The text was updated successfully, but these errors were encountered: