diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 30f2443c63..6dc25c8fe3 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -4397,14 +4397,9 @@ Document::findObjects(const Base::Type& typeId, const char* objname, const char* int Document::countObjectsOfType(const Base::Type& typeId) const { - int ct = 0; - for (const auto& it : d->objectMap) { - if (it.second->getTypeId().isDerivedFrom(typeId)) { - ct++; - } - } - - return ct; + return std::count_if(d->objectMap.begin(), d->objectMap.end(), [&](const auto& it) { + return it.second->getTypeId().isDerivedFrom(typeId); + }); } int Document::countObjectsOfType(const char* typeName) const diff --git a/src/Gui/Selection.cpp b/src/Gui/Selection.cpp index 6a5925fd51..bef006fd72 100644 --- a/src/Gui/Selection.cpp +++ b/src/Gui/Selection.cpp @@ -526,7 +526,6 @@ std::vector SelectionSingleton::getObjectsOfType(const cha unsigned int SelectionSingleton::countObjectsOfType(const Base::Type& typeId, const char* pDocName, ResolveMode resolve) const { - unsigned int iNbr=0; App::Document *pcDoc = nullptr; if(!pDocName || strcmp(pDocName,"*") != 0) { pcDoc = getDocument(pDocName); @@ -534,12 +533,9 @@ unsigned int SelectionSingleton::countObjectsOfType(const Base::Type& typeId, co return 0; } - for (auto &sel : _SelList) { - if((!pcDoc||pcDoc==sel.pDoc) && getObjectOfType(sel, typeId, resolve)) - iNbr++; - } - - return iNbr; + return std::count_if(_SelList.begin(), _SelList.end(), [&](auto& sel) { + return (!pcDoc || pcDoc == sel.pDoc) && getObjectOfType(sel, typeId, resolve); + }); } unsigned int SelectionSingleton::countObjectsOfType(const char* typeName, const char* pDocName, ResolveMode resolve) const