I have two versions of operator():
const A& operator(int x ,int y) const;
A& operator(int x ,int y);
But I don't know what would be the best way to avoid code repetition (because they essentially have the same logic).
I did read the awesome FAQ regarding operator overloading (and some other questions) but did not find answer.
EDIT_1: I've tried the suggestion that Skizz proposed but something like that does not quite work for me but maybe I've missed something:
Because this works while this does not compile giving the following error:
error: invalid initialization of reference of type ‘int&’ from expression of type ‘const value_type {aka const int}’