As a follow-up to this question, I need a way to access my data by index. But the data needs to be sorted by timestamp, contain a filepath as a value, and be displayed in real-time as new elements are discovered.
Considering that multiple files/folders could potentially contain an identical timestamp, I've decided to go with std::multimap
as the container of choice to store my data. However, this complicates the process of populating my List Control, since LVITEM::iItem
is an index value used to determine which element of data is to be displayed in a control with the LVS_OWNERDATA
flag set (i.e., virtual lists).
I can't seem to find a way to access my data by index in order to get the timestamp keys & filepath values, so what could I do to correct this issue?
You cannot access the content of a
std::multimap
by index directly. But what you can do is store your sorted data in astd::multimap
and then storeiterator
values in a separatestd::vector
and use that as the data source for your ListView. When the ListView asks for data by index, go to yourstd::vector
and use theiterator
at the specified index to access your data in thestd::multimap
. When youinsert()
a new item in astd::multimap()
, it returns aniterator
for that item, and existingiterator
s are not invalidated by inserts.