I have to type of very complex object A and B in 2 vectors:
vector<A> va; vector<B> vb
I want to loop over
va
andvb
, and store pairs in a C++ container:for(i:va) for(j:vb) container[i]=[j]
notice that the container can have several time the same "key" object.
- I wanted to use a multimap but
A
andB
are very complex compound data type and I do not want to slim information when setting the "key". - My final goal is to be able to access information for
i
and its correspondingj
in the container. - Do you know which container is suitable for this task?
Asked
Active
Viewed 36 times
0

Lightness Races in Orbit
- 378,754
- 76
- 643
- 1,055

cabe
- 115
- 2
- 8
-
You *could* store pairs of iterators in the multimap.. Assuming the vectors aren't updated after some point in time, and the iterators aren't invalidated. – StoryTeller - Unslander Monica Sep 06 '16 at 16:48
-
It is not clear what 'slim information when setting the "key"' means. Could you rephrase that? – Beta Sep 06 '16 at 16:51
-
What about a multimap containing pointers to elements in `va` and `vb`? – Tristan Brindle Sep 06 '16 at 16:51
-
StoryTeller: your solution seem complicate – cabe Sep 06 '16 at 16:55
-
Beta: I mean that I want to be able to keep all the information of the object. – cabe Sep 06 '16 at 16:55
-
Tristan: your idea is quite interesting. I'll try this and see. – cabe Sep 06 '16 at 16:56
-
Thank you all for your help. – cabe Sep 06 '16 at 16:56