At some point I will write a page about indexitor, it's rationale and
how to use it but briefly:
you want a sequence container of items that include a reference to an
element in another (foreign) container, so you could use:
std::vector<std::pair<foo, foreign_iterator>>
but this is no good if the foreign container iterators can be
invalidated if changes (insert/erase element) are made to the foreign
container however if the foreign container can be indexed numerically
(for e.g. by vector::operator[] or std::deque::operator[]) then you
could use:
std::vector<std::pair<foo, std::size_t>>
where the second item is the index to the foreign container element
HOWEVER if you change the foreign container (insert/erase element) you
will have to update all indexes after the change which is O(n)
complexity but with:
indexitor<foo, std::size_t>
the same can be achieved with O(lg N) complexity. How does this work?
Well instead of storing indexes we store intervals and we use a tree to
allow O(lg N) complexity indexing.
A common mistake might be to think that I am reimplementing std::map but
indexitor is not an associative container: it is a sequence container
with random access like vector or deque. Also std::map is a single
container whilst this is a solution that allows us to have multiple
foreign containers.
/Flibble