我的同事声称对于对象类型,preincrement比post增量更有效
例如
std::vector<std::string> vec;
... insert a whole bunch of strings into vec ...
// iterate over and do stuff with vec. Is this more efficient than the next
// loop?
std::vector<std::string>::iterator it;
for (it = vec.begin(); it != vec.end(); ++it){
}
// iterate over and do stuff with vec. Is this less efficient than the previous loop?
std::vector<std::string>::iterator it;
for (it = vec.begin(); it != vec.end(); it++){
}
Run Code Online (Sandbox Code Playgroud) 我有以下方法C++,只tableId从地图中删除与特定关联的元素.
69 void
70 ObjectFinder::flush(uint64_t tableId) {
71
72 RAMCLOUD_TEST_LOG("flushing object map");
74 // find everything between tableId, 0
75 // keep scanning util find all the entries for that table
76 std::map<TabletKey, ProtoBuf::Tablets::Tablet>::const_iterator it;
79 for (it = tableMap.begin(); it != tableMap.end(); it++) {
80 TabletKey current = it->first;
81 if (tableId == current.first) {
82 tableMap.erase(current);
83 }
84 }
85 std::cout << "hello" << std::endl;
87 }
Run Code Online (Sandbox Code Playgroud)
进入代码时gdb我发现在循环迭代后发生了无限for循环.该行85 …