From c11ec0a6fd57d3c4009d1cc4274fdf1298bf2c12 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 21 Jun 2020 02:29:23 -0400 Subject: [PATCH] CDependencyGroup: Make use of ranged for --- src/Core/Resource/CDependencyGroup.h | 31 ++++++++++++---------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Core/Resource/CDependencyGroup.h b/src/Core/Resource/CDependencyGroup.h index 130ab744..9ddc6b78 100644 --- a/src/Core/Resource/CDependencyGroup.h +++ b/src/Core/Resource/CDependencyGroup.h @@ -2,6 +2,7 @@ #define CDEPENDENCYGROUP #include "CResource.h" +#include class CDependencyGroup : public CResource { @@ -21,33 +22,27 @@ public: mDependencies.push_back(rkID); } - void AddDependency(CResource *pRes) + void AddDependency(const CResource* pRes) { - if ( pRes && !HasDependency(pRes->ID()) ) + if (pRes != nullptr && !HasDependency(pRes->ID())) mDependencies.push_back(pRes->ID()); } void RemoveDependency(const CAssetID& rkID) { - for (auto Iter = mDependencies.begin(); Iter != mDependencies.end(); Iter++) - { - if (*Iter == rkID) - { - mDependencies.erase(Iter); - return; - } - } + const auto it = std::find_if(mDependencies.cbegin(), mDependencies.cend(), + [&rkID](const auto& entry) { return entry == rkID; }); + + if (it == mDependencies.cend()) + return; + + mDependencies.erase(it); } - bool HasDependency(const CAssetID &rkID) const + bool HasDependency(const CAssetID& rkID) const { - for (uint32 iDep = 0; iDep < mDependencies.size(); iDep++) - { - if (mDependencies[iDep] == rkID) - return true; - } - - return false; + return std::any_of(mDependencies.cbegin(), mDependencies.cend(), + [&rkID](const auto& entry) { return entry == rkID; }); } std::unique_ptr BuildDependencyTree() const