Nick Stokes
I have a stream of pairs of elements of type T, and want to insert individual T's uniquely into a container and convert the pairs to a pair of indices into this container [...]
typedef bmi::multi_index_container< T, bmi::indexed_by < bmi::hashed_unique< bmi::identity<T> > , bmi::random_access<> >> MIC;
[...]
auto index_of = [&]( MIC::const_iterator i ) { return elements.project<1>(i) - elements.get<1>().begin(); }
So my questions are
(1) Is the implementation of index_of() correct? (or better, is there something like this already for random access indices)
This is correct and gives you the *insertion* order, if this is indeed what you're interested in.
(2) Is the way they are used in above loop stable, where elements are inserted after an index is obtained?
It is stable as long as you don't erase elements. HTH Joaquín M López Muñoz Telefónica