Am 08.09.2016 um 21:06 schrieb Joaquin M López Muñoz:
El 08/09/2016 a las 19:17, Deniz Bahadir escribió:
Am 08.09.2016 um 18:39 schrieb Joaquin M López Muñoz:
El 08/09/2016 a las 18:22, Deniz Bahadir escribió: So, just to make sure: This second solution would even work if Index2 is unique and I have a
collision with key2 (as my example code would definitively have)?
Correct. The only thing you have to be careful about is not to touch key1, as the element would be repositioned (according to the order of Index1) and your iterator would end up somewhere else within/outside the range.
However, the side effect would be, that I end up erasing all elements of my range except for the first? (Or even erasing that first element, too, if the database already contains another element outside my range with that same value for key2.)
Yes, if your changing the key produces a collision, the element is erased. Depending on your use case, you might want to consider other approaches:
- replace() is passed a new element rather than let you change the existing one: if a collision would ensue, replace() does not change the original element. - There is a rollback-equipped version of modify() where you can undo collision-producing changes.
Joaquín M López Muñoz
Thank you very much, Joaquín. This helps a lot. Deniz