Suppose I have several nested structs in C++, like this:
struct Size { int width, height; }; struct Position { int x, y; }; struct Layout { Size size; Position position; }; class Container { public: Layout layout; void onLayoutChanged(); // should be called when any field inside layout changes }; If I do something like container.layout.size.width = 100;, I want container.onLayoutChanged() to be automatically called.
Is there a clean or idiomatic way in C++ to achieve this kind of automatic notification whenever any nested field changes? Ideally, without having to manually trigger the notification every time.
Are there any patterns or utilities in modern C++ (C++17/20/23) that help with this kind of problem?
struct Changeobject? You want different hooks for different instances?