typedef map<int, string> iMap;
typedef map<double, innerMap> OutMap;
OutMap mx;
map<double, iMap >::iterator it_out;
map<int, string>::iterator it_i;
for ( it_out=mx.begin() ; it_out != mx.end(); it_out++ ) {
cout << "\n\nNew element\n" << (*it_out).first << endl;
for( it_i=(*it_out).second.begin(); it_i != (*it_out).second.end(); it_out++)
cout << (*it_i).first << " => " << (*it_i).second << endl;
}
I’m pretty sure the above code is fine…
Is there any performance issue…?
It cannot be improved further, except that
++it_outinstead ofit_out++.'\n'instead ofendlin the cout. Using'\n'would improve the performance of output operation by reasonable margin, becauseendlfirst puts'\n'in the output buffer, and then flushes it to the destination (stdoutin this case) which makes it slow operation.Note that you should increment
it_i(as opposed toit_out) in the innerforloop. I suppose that is a typo.