
Briefly put, there is no way to do that. The only thing that will work, though it's not officially guaranteed by the implementation, is:
* Modify ONE element without using replace() or modify() (by using a const_cast, basically.) * Before doing anything else with the container (except possibly accessing their elements through previously existing iterators and/or advance those iterators around), use modify() with a no-op functor, as you suggest.
I see... Unfortunately, it doesn't fit my use-case. I store weak_ptr's, and my key extractors have to return different results for expired and non-expired weak_ptr's.
But you just can't externally (with const_cast) modify a bunch of elements and then get the index to rebuild --the rebuilding machinery assumes that at most one element (the one you call modify() on) is out of place, so if other elements are shuffled as well you'll get some sort of undefined behavior: core dump, whatever.
What if I just copy all the elements to another container of the same type? Will the iteration from begin() from end() work correctly?