ValueType getItem(IndexType i);void setItem(IndexType i, ValueType val);
ValueType& operator[](IndexType i);
class Mediator{ IndexType index;public: Mediator(IndexType i):index(i) {} ValueType operator=(ValueType value) { setItem(index, value); return value; } operator ValueType() { return getItem(index); }};....Mediator operator[](IndexType i){ return Mediator(i);}
template<class cont_tp, class key_tp, class val_tp> class access_operator{ cont_tp *data; const key_tp& ind;public: access_operator(cont_tp *d, const key_tp& i):data(d),ind(i) {} const val_tp& operator=(const val_tp& val) { data->set_item(ind, val); return val; } operator const val_tp&() const { return data->get_item(ind); }};
template<class key_other> int& operator[](const key_other& k){ return (data->modify_item(ind))[k];}
template<class key_other, class val_other> val_other operator[](const key_other& k){ return (data->modify_item(ind))[k];}