I have a C++ class which simulates an array and for manipulating its members I implemented two functions: set(size_t index, size_t value) and get(size_t index). I would like to overload the [] operator to have the following functionality:
MyCustomArray[index] = value //->set(size_t index, size_t value)
And
value = MyCustomArray[index] //->get(size_t index)
get can be easily implemented with overload, but I don't know how to implement set because I need the parameter value beforehand.
My class is an implementation of a fixed-word array (elements in the array have at most P bits, where P is a parameter and it can be less than the regular machine word). To support this functionality, set and get manipulate a range of bits of a value in a regular C/C++ array.
Is it possible to overload in this scenario?
Thanks in advance!
std::vector<bool>and return a temporary proxy object that itself overloadsoperator =.std::vectorbreaking generic code, but it's a good example for the needed functionality.