I wonder if it is possible to write, for some class, an operator[] which distinguishes between read and write access, to keep track of properties of the data content of an object.
1 2 3 4 5 6 7
class Test {
T x[10];
bool some_property;
public:
const T & operator[] (int i) const { return x[i]; }
T & operator[] (int i) { some_property = false; return x[i]; }
};
This code is setting some_property to false on any read or write access to a non-const object. But this should be done only on write.
I could write Test::set() and Test::get(), but it's of course nicer to let the operator[] handle it properly. Is this possible?