diff --git a/Common/Data/Format/IniFile.cpp b/Common/Data/Format/IniFile.cpp index 829f09097b..9c88ca432c 100644 --- a/Common/Data/Format/IniFile.cpp +++ b/Common/Data/Format/IniFile.cpp @@ -191,9 +191,9 @@ void Section::Clear() { bool Section::GetKeys(std::vector &keys) const { keys.clear(); - for (auto liter = lines_.begin(); liter != lines_.end(); ++liter) { - if (!liter->Key().empty()) - keys.emplace_back(liter->Key()); + for (auto &line : lines_) { + if (!line.Key().empty()) + keys.emplace_back(line.Key()); } return true; } @@ -303,11 +303,10 @@ void Section::Set(std::string_view key, bool newValue, bool defaultValue) void Section::Set(std::string_view key, const std::vector& newValues) { std::string temp; - // Join the strings with , - std::vector::const_iterator it; - for (it = newValues.begin(); it != newValues.end(); ++it) + // Join the strings with , + for (const auto &value : newValues) { - temp += (*it) + ","; + temp += value + ","; } // remove last , if (temp.length()) @@ -668,25 +667,3 @@ bool IniFile::Get(const char* sectionName, const char* key, bool* value, bool de return section->Get(key, value, defaultValue); } } - - -// Unit test. TODO: Move to the real unit test framework. -/* - int main() - { - IniFile ini; - ini.Load("my.ini"); - ini.Set("Hej", "A", "amaskdfl"); - ini.Set("Mossa", "A", "amaskdfl"); - ini.Set("Aissa", "A", "amaskdfl"); - //ini.Read("my.ini"); - std::string x; - ini.Get("Hej", "B", &x, "boo"); - ini.DeleteKey("Mossa", "A"); - ini.DeleteSection("Mossa"); - ini.SortSections(); - ini.Save("my.ini"); - //UpdateVars(ini); - return 0; - } - */ diff --git a/Common/Data/Text/I18n.cpp b/Common/Data/Text/I18n.cpp index bcd2237c48..43f18e62e8 100644 --- a/Common/Data/Text/I18n.cpp +++ b/Common/Data/Text/I18n.cpp @@ -103,11 +103,11 @@ const char *I18NCategory::T_cstr(const char *key, const char *def) { } void I18NCategory::SetMap(const std::map &m) { - for (auto iter = m.begin(); iter != m.end(); ++iter) { - if (map_.find(iter->first) == map_.end()) { - std::string text = ReplaceAll(iter->second, "\\n", "\n"); - _dbg_assert_(iter->first.find('\n') == std::string::npos); - map_[iter->first] = I18NEntry(text); + for (const auto &[key, value] : m) { + if (map_.find(key) == map_.end()) { + std::string text = ReplaceAll(value, "\\n", "\n"); + _dbg_assert_(key.find('\n') == std::string::npos); + map_[key] = I18NEntry(text); } } } diff --git a/Common/File/VFS/ZipFileReader.cpp b/Common/File/VFS/ZipFileReader.cpp index fa416eef04..99a6083ee3 100644 --- a/Common/File/VFS/ZipFileReader.cpp +++ b/Common/File/VFS/ZipFileReader.cpp @@ -110,13 +110,13 @@ bool ZipFileReader::GetFileListing(const char *orig_path, std::vectorreserve(directories.size() + files.size()); - for (auto diter = directories.begin(); diter != directories.end(); ++diter) { + for (const auto &dir : directories) { File::FileInfo info; - info.name = *diter; + info.name = dir; // Remove the "inzip" part of the fullname. std::string relativePath = std::string(path).substr(inZipPath_.size()); - info.fullName = Path(relativePath + *diter); + info.fullName = Path(relativePath + dir); info.exists = true; info.isWritable = false; info.isDirectory = true; @@ -124,12 +124,12 @@ bool ZipFileReader::GetFileListing(const char *orig_path, std::vectorpush_back(info); } - for (auto fiter = files.begin(); fiter != files.end(); ++fiter) { + for (const auto &fiter : files) { std::string fpath = path; File::FileInfo info; - info.name = *fiter; + info.name = fiter; std::string relativePath = std::string(path).substr(inZipPath_.size()); - info.fullName = Path(relativePath + *fiter); + info.fullName = Path(relativePath + fiter); info.exists = true; info.isWritable = false; info.isDirectory = false; diff --git a/Common/Input/InputState.cpp b/Common/Input/InputState.cpp index 1d94e8d590..e766bf2c3e 100644 --- a/Common/Input/InputState.cpp +++ b/Common/Input/InputState.cpp @@ -42,8 +42,8 @@ std::vector tabRightKeys; static std::unordered_map uiFlipAnalogY; static void AppendKeys(std::vector &keys, const std::vector &newKeys) { - for (auto iter = newKeys.begin(); iter != newKeys.end(); ++iter) { - keys.push_back(*iter); + for (auto key : newKeys) { + keys.push_back(key); } } diff --git a/Common/Net/HTTPServer.cpp b/Common/Net/HTTPServer.cpp index 623726cfca..5d2f85c98e 100644 --- a/Common/Net/HTTPServer.cpp +++ b/Common/Net/HTTPServer.cpp @@ -359,8 +359,8 @@ void Server::Handle404(const ServerRequest &request) { void Server::HandleListing(const ServerRequest &request) { request.WriteHttpResponseHeader("1.0", 200, -1, "text/plain"); - for (auto iter = handlers_.begin(); iter != handlers_.end(); ++iter) { - request.Out()->Printf("%s\n", iter->first.c_str()); + for (auto &handler : handlers_) { + request.Out()->Printf("%s\n", handler.first.c_str()); } } diff --git a/Common/Serialize/SerializeList.h b/Common/Serialize/SerializeList.h index d42ddc80f5..db17b0870d 100644 --- a/Common/Serialize/SerializeList.h +++ b/Common/Serialize/SerializeList.h @@ -27,9 +27,8 @@ void DoList(PointerWrap &p, std::list &x, T &default_val) { Do(p, list_size); x.resize(list_size, default_val); - typename std::list::iterator itr, end; - for (itr = x.begin(), end = x.end(); itr != end; ++itr) - Do(p, *itr); + for (T elem : x) + Do(p, elem); } template diff --git a/Common/Serialize/SerializeMap.h b/Common/Serialize/SerializeMap.h index 641dd9bae7..294266b930 100644 --- a/Common/Serialize/SerializeMap.h +++ b/Common/Serialize/SerializeMap.h @@ -62,8 +62,8 @@ void DoMap(PointerWrap &p, M &x, typename M::mapped_type &default_val) { template void Do(PointerWrap &p, std::map &x) { if (p.mode == PointerWrap::MODE_READ) { - for (auto it = x.begin(), end = x.end(); it != end; ++it) { - delete it->second; + for (auto &iter : x) { + delete iter.second; } } T *dv = nullptr; @@ -79,8 +79,8 @@ void Do(PointerWrap &p, std::map &x) { template void Do(PointerWrap &p, std::unordered_map &x) { if (p.mode == PointerWrap::MODE_READ) { - for (auto it = x.begin(), end = x.end(); it != end; ++it) { - delete it->second; + for (auto &iter : x) { + delete iter.second; } } T *dv = nullptr; @@ -132,8 +132,8 @@ void DoMultimap(PointerWrap &p, M &x, typename M::mapped_type &default_val) { template void Do(PointerWrap &p, std::multimap &x) { if (p.mode == PointerWrap::MODE_READ) { - for (auto it = x.begin(), end = x.end(); it != end; ++it) { - delete it->second; + for (auto &iter : x) { + delete iter.second; } } T *dv = nullptr; @@ -149,8 +149,8 @@ void Do(PointerWrap &p, std::multimap &x) { template void Do(PointerWrap &p, std::unordered_multimap &x) { if (p.mode == PointerWrap::MODE_READ) { - for (auto it = x.begin(), end = x.end(); it != end; ++it) { - delete it->second; + for (auto &iter : x) { + delete iter.second; } } T *dv = nullptr; diff --git a/Common/Serialize/SerializeSet.h b/Common/Serialize/SerializeSet.h index 7917f51f52..e3684a5167 100644 --- a/Common/Serialize/SerializeSet.h +++ b/Common/Serialize/SerializeSet.h @@ -54,8 +54,14 @@ void DoSet(PointerWrap &p, std::set &x) { template void Do(PointerWrap &p, std::set &x) { if (p.mode == PointerWrap::MODE_READ) { +<<<<<<< HEAD for (auto it = x.begin(), end = x.end(); it != end; ++it) { delete *it; +======= + for (T* s : x) { + if (s != nullptr) + delete s; +>>>>>>> 37ce2a4de1 ([Common/Data/File/Input/Net/Serialize/System/UI] Using for based loop C++17 and replaced on structured binding map C++17) } } DoSet(p, x); diff --git a/Common/UI/Root.cpp b/Common/UI/Root.cpp index 41dadf3d16..7c0dc97b5a 100644 --- a/Common/UI/Root.cpp +++ b/Common/UI/Root.cpp @@ -353,21 +353,21 @@ static void ProcessHeldKeys(ViewGroup *root) { double now = time_now_d(); restart: - for (std::set::iterator iter = heldKeys.begin(); iter != heldKeys.end(); ++iter) { - if (iter->triggerTime < now) { + for (const auto &hk : heldKeys) { + if (hk.triggerTime < now) { KeyInput key; - key.keyCode = iter->key; - key.deviceId = iter->deviceId; + key.keyCode = hk.key; + key.deviceId = hk.deviceId; key.flags = KEY_DOWN; KeyEvent(key, root); focusMoves.push_back(key.keyCode); // Cannot modify the current item when looping over a set, so let's do this instead. - HeldKey hk = *iter; - heldKeys.erase(hk); - hk.triggerTime = now + repeatInterval; - heldKeys.insert(hk); + HeldKey k = hk; + heldKeys.erase(k); + k.triggerTime = now + repeatInterval; + heldKeys.insert(k); goto restart; } } diff --git a/Common/UI/Screen.cpp b/Common/UI/Screen.cpp index 345f06b9de..7f88d7648e 100644 --- a/Common/UI/Screen.cpp +++ b/Common/UI/Screen.cpp @@ -163,8 +163,8 @@ void ScreenManager::resized() { std::lock_guard guard(inputLock_); // Have to notify the whole stack, otherwise there will be problems when going back // to non-top screens. - for (auto iter = stack_.begin(); iter != stack_.end(); ++iter) { - iter->screen->resized(); + for (auto &layer : stack_) { + layer.screen->resized(); } } @@ -338,8 +338,8 @@ void ScreenManager::pop() { void ScreenManager::RecreateAllViews() { std::lock_guard guard(inputLock_); - for (auto it = stack_.begin(); it != stack_.end(); ++it) { - it->screen->RecreateViews(); + for (auto &layer : stack_) { + layer.screen->RecreateViews(); } } diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 09084b0516..8075c4cdae 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -77,8 +77,8 @@ void Event::Trigger(EventParams &e) { // Call this from UI thread EventReturn Event::Dispatch(EventParams &e) { - for (auto iter = handlers_.begin(); iter != handlers_.end(); ++iter) { - if ((iter->func)(e) == UI::EVENT_DONE) { + for (auto &handler : handlers_) { + if ((handler.func)(e) == UI::EVENT_DONE) { // Event is handled, stop looping immediately. This event might even have gotten deleted. return UI::EVENT_DONE; } diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index d85406201c..a544952929 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -438,9 +438,9 @@ NeighborResult ViewGroup::FindNeighbor(View *view, FocusDirection direction, Nei } // Then go right ahead and see if any of the children contain any better candidates. - for (auto iter = views_.begin(); iter != views_.end(); ++iter) { - if ((*iter)->IsViewGroup()) { - ViewGroup *vg = static_cast(*iter); + for (auto *v : views_) { + if (v->IsViewGroup()) { + ViewGroup *vg = static_cast(v); if (vg) result = vg->FindNeighbor(view, direction, result); }