I have custom C++ container class representing my table class (
MyTable). Each row of such table has a wrapper class
MyRow containing some private members and a pointer to the actual data buffer for this row, located inside some continuous buffer, that is property of
I want to implement a sort method for
std::sort. I have defined my iterator class knowing to work with
After testing my application, I noticed that the sort execution damages all data in the table overriding all rows with the data belonging to 1st row. After debugging this issue, I figured out, that the following pointer dereference operator is core of the problem:
MyRow& MyTableIterator::operator* () const;
When sort engine tries to swap data in 2 rows of
MyTable, it introduces temporary variable of
MyRow type. The problem is that
MyRow is only wrapper class around actual data, and 2 cloned
MyRow objects simply point to the same data. As result, the swap is not working.
My questing is what can I do in this case? Is it possible to overcome my problem and still to use
std::sort or do I need to implement my own sort method?