A cross between std::multimap and std::vector?
Posted
by Milan Babuškov
on Stack Overflow
See other posts from Stack Overflow
or by Milan Babuškov
Published on 2010-05-30T11:26:02Z
Indexed on
2010/05/30
11:32 UTC
Read the original article
Hit count: 386
I'm looking for a STL container that works like std::multimap, but has constant access time to random n-th element. I need this because I have such structure in memory that is std::multimap for many reasons, but items stored in it have to be presented to the user in a listbox. Since amount of data is huge, I'm using list box with virtual items (i.e. list control polls for value at line X).
As a workaround I'm currently using additional std::vector to store "indexes" into std::map, and I fill it like this:
std::vector<MMap::data_type&> vec;
for (MMap::iterator it = mmap.begin(); it != mmap.end(); ++it)
vec.push_back((*it).second);
But this is not very elegant solution.
Is there some such containter?
© Stack Overflow or respective owner