I need to allow the user to change members of two data structures of the same type at the same time. For example:
struct Foo { int a, b; }
Foo a1 = {1,2}, a2 = {3,4};
dual(a1,a2)->a = 5;
// Now a1 = {5,2} and a2 = {5,2}
I have a class that works and that change first a1 and then copy a1 into a2. This is fine as long as:
the class copied is small
the user doesn't mind about everything being copied, not only the part modified.
Is there a way to obtain this behavior:
dual(a1,a2)->a = 5;
// Now a1 = {5,2} and a2 = {5,4}
I am opened to alternative syntax, but they should stay simple, and I would like to avoid things like:
set_members(a1, a2, &Foo::a, 5);
members(a1, a2, &Foo::a) = 5;
or anything involving specifying explictely &Foo::