From b77f52bb0e14976d80f611e27e0d6d3d3b886779 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 18 Jun 2020 06:14:48 -0400 Subject: [PATCH] CResTypeFilter: Make use of ranged for where applicable We can also collapse a loop down into a std::any_of. --- src/Core/Resource/CResTypeFilter.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Core/Resource/CResTypeFilter.h b/src/Core/Resource/CResTypeFilter.h index 5e220546..cdbd3b22 100644 --- a/src/Core/Resource/CResTypeFilter.h +++ b/src/Core/Resource/CResTypeFilter.h @@ -5,6 +5,8 @@ #include "CResTypeInfo.h" #include "Core/GameProject/CResourceEntry.h" +#include + class CResTypeFilter { EGame mGame = EGame::Invalid; @@ -19,9 +21,9 @@ public: mAcceptedTypes.clear(); mGame = Game; - for (auto Iter = rkTypes.begin(); Iter != rkTypes.end(); Iter++) + for (const auto& str : rkTypes) { - CResTypeInfo *pTypeInfo = CResTypeInfo::TypeForCookedExtension(mGame, CFourCC(*Iter)); + CResTypeInfo* pTypeInfo = CResTypeInfo::TypeForCookedExtension(mGame, CFourCC(str)); if (pTypeInfo) mAcceptedTypes.insert(pTypeInfo->Type()); @@ -32,10 +34,12 @@ public: { TString Out; - for (auto Iter = mAcceptedTypes.begin(); Iter != mAcceptedTypes.end(); Iter++) + for (const auto type : mAcceptedTypes) { - if (!Out.IsEmpty()) Out += ','; - CResTypeInfo *pTypeInfo = CResTypeInfo::FindTypeInfo(*Iter); + if (!Out.IsEmpty()) + Out += ','; + + CResTypeInfo *pTypeInfo = CResTypeInfo::FindTypeInfo(type); Out += pTypeInfo->CookedExtension(mGame).ToString(); } @@ -68,15 +72,10 @@ public: return pEntry && Accepts(pEntry->ResourceType()); } - bool Accepts(const CResTypeFilter& rkFilter) const + bool Accepts(const CResTypeFilter& filter) const { - for (auto Iter = mAcceptedTypes.begin(); Iter != mAcceptedTypes.end(); Iter++) - { - if (rkFilter.Accepts(*Iter)) - return true; - } - - return false; + return std::any_of(mAcceptedTypes.cbegin(), mAcceptedTypes.cend(), + [&filter](const auto& entry) { return filter.Accepts(entry); }); } bool operator==(const CResTypeFilter& rkOther) const