I want to store a different order for the pairs in std::map<string,void*> by pushing the pointers to pairs in the map on to a vector<pair<string,void*>*> in a desired order. How to get the pointer to each pair in the map?
3 Answers
If you dereference an iterator of the map, you get a reference to the pair. Taking the address of that gives you a pointer to the pair.
auto it = map.begin();
auto ptr = &*it;
Use care when declaring the pair, though, as the first element is const: pair<const string, void *>. Or use std::map<string,void*>::value_type instead of pair.
std::vector<std::map<string,void*>::iterator>or maybe evenstd::vector<std::map<string,void*>::const_iterator>if applicable.