Lunderberg commented on PR #16832: URL: https://github.com/apache/tvm/pull/16832#issuecomment-2045487082
In the future, I'm wondering if the `CopyOnWrite` functionality should be extended to perform this type of initialization. Currently, regardless of what invariants are established by an object's constructor, they can be violated when overwritten with `CopyOnWrite`. We could have `CopyOnWrite` return a proxy object, rather than `T::ContainerType*`. The proxy object would provide `operator->`, so the same `obj.CopyOnWrite()->foo = new_foo` would still function as intended. However, on destruction, the proxy object would call some `T::Validate` method. That way, we get the usability of direct access and CoW to mutating a single field, but we can still establish invariants for classes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
