mardi 3 août 2021

why my map loop more than once when my map.size()=1?

I have a two-level unordered_map:

std::unordered_map<std::string, std::unordered_map<std::string, mystruct*> > a;

I also have a function to get the second level map:

const std::unordered_map<std::string, mystruct*> get_map(const std::string& ticker) {
  return a[ticker];
}

then, i loop this map to get data:

const auto& m = get_map("ticker");  // this map.size() = 1
for (const auto & i : m) {
  // but this for, loop more than once, and the data is mess code
}

could you help on this?

i know this is not a runnable demo, i am trying to reproduce this, bc this comes from a big project.

i will be grateful if you have offer some tips.

Aucun commentaire:

Enregistrer un commentaire