OK, this is not a bug in Boost.MultiIndex, but a subtle contract violation in your code. The pointerless version:
auto iter = dataContainer.get<0>().find(1);
Data d = *iter;
d.key2 = 5;
dataContainer.replace(iter, d);
is taking a copy of the contained value into d
, modifying it and then using it for replacement: so far so good. But the pointer version is breaking invariants along the way:
auto iter = dataContainer.get<0>().find(1);
Data* d = *iter;
d->key2 = 5; // #1: invariant breach here
dataContainer.replace(iter, d); // #2: unexpected behavior ensues
In #1, you're modifying an internal key of dataContainer
without its consent or knowledge: once you've done that, the touched element is incorrectly indexed. This is analogous to casting constness away in the pointerless version:
auto iter = dataContainer.get<0>().find(1);
const Data& d = *iter;
const_cast<Data&>(d).key2 = 5;
So, when #2 is executed, datacontainer
, which does not suspect you've changed its keys, simply verifies that your proposed replacement d
is equivalent to what it already has, and does nothing (no reindexing then).