From 4a16ea41a7e758017ae9476722c75980cd1a525f Mon Sep 17 00:00:00 2001 From: bofdahof <172177156+bofdahof@users.noreply.github.com> Date: Wed, 12 Mar 2025 17:46:30 +1000 Subject: [PATCH] App: apply std::ranges --- src/App/Branding.cpp | 2 +- src/App/Datums.cpp | 10 +++++----- src/App/Document.cpp | 8 ++++---- src/App/DocumentObject.cpp | 4 ++-- src/App/GeoFeatureGroupExtension.cpp | 4 ++-- src/App/Graphviz.cpp | 2 +- src/App/GroupExtension.cpp | 2 +- src/App/ProgramOptionsUtilities.h | 2 +- src/App/PropertyExpressionEngine.cpp | 18 ++++++++---------- 9 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/App/Branding.cpp b/src/App/Branding.cpp index c3ddfe01d2..ae9052d123 100644 --- a/src/App/Branding.cpp +++ b/src/App/Branding.cpp @@ -92,7 +92,7 @@ Branding::XmlConfig Branding::getUserDefines() const while (!child.isNull()) { std::string name = child.localName().toLatin1().constData(); std::string value = child.text().toUtf8().constData(); - if (std::find(filter.begin(), filter.end(), name) != filter.end()) { + if (std::ranges::find(filter, name) != filter.end()) { cfg[name] = value; } child = child.nextSiblingElement(); diff --git a/src/App/Datums.cpp b/src/App/Datums.cpp index 38d214575e..f595277856 100644 --- a/src/App/Datums.cpp +++ b/src/App/Datums.cpp @@ -208,7 +208,7 @@ App::Point* LocalCoordinateSystem::getPoint(const char* role) const bool LocalCoordinateSystem::hasObject(const DocumentObject* obj) const { const auto& features = OriginFeatures.getValues(); - return std::find(features.begin(), features.end(), obj) != features.end(); + return std::ranges::find(features, obj) != features.end(); } short LocalCoordinateSystem::mustExecute() const @@ -302,12 +302,12 @@ void LocalCoordinateSystem::unsetupObject() { const auto& objsLnk = OriginFeatures.getValues(); // Copy to set to assert we won't call method more then one time for each object - std::set objs(objsLnk.begin(), objsLnk.end()); + const std::set objs(objsLnk.begin(), objsLnk.end()); // Remove all controlled objects for (auto obj : objs) { // Check that previous deletes didn't indirectly remove one of our objects - const auto& objsLnk = OriginFeatures.getValues(); - if (std::find(objsLnk.begin(), objsLnk.end(), obj) != objsLnk.end()) { + const auto& objsLnk2 = OriginFeatures.getValues(); + if (std::ranges::find(objsLnk2, obj) != objsLnk2.end()) { if (!obj->isRemoving()) { obj->getDocument()->removeObject(obj->getNameInDocument()); } @@ -331,7 +331,7 @@ void LocalCoordinateSystem::migrateOriginPoint() return obj->isDerivedFrom() && strcmp(static_cast(obj)->Role.getValue(), PointRoles[0]) == 0; }; - if (std::none_of(features.begin(), features.end(), isOrigin)) { + if (std::ranges::none_of(features, isOrigin)) { auto data = getData(PointRoles[0]); auto* origin = createDatum(data); origin->purgeTouched(); diff --git a/src/App/Document.cpp b/src/App/Document.cpp index d843343c9b..fa86e8c57c 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -4304,7 +4304,7 @@ void DocumentP::findAllPathsAt(const std::vector& all_nodes, std::vector& all_paths, Path tmp) { - if (std::find(tmp.begin(), tmp.end(), id) != tmp.end()) { + if (std::ranges::find(tmp, id) != tmp.end()) { Path tmp2(tmp); tmp2.push_back(id); all_paths.push_back(tmp2); @@ -4352,10 +4352,10 @@ Document::getPathsByOutList(const App::DocumentObject* from, const App::Document DocumentP::findAllPathsAt(all_nodes, index_from, all_paths, tmp); for (const Path& it : all_paths) { - Path::const_iterator jt = std::find(it.begin(), it.end(), index_to); + auto jt = std::ranges::find(it, index_to); if (jt != it.end()) { - std::list path; - for (Path::const_iterator kt = it.begin(); kt != jt; ++kt) { + std::list path; + for (auto kt = it.begin(); kt != jt; ++kt) { path.push_back(d->objectArray[*kt]); } diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 138161db7f..2b99aa7d7d 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -590,7 +590,7 @@ bool DocumentObject::isInInListRecursive(DocumentObject* linkTo) const bool DocumentObject::isInInList(DocumentObject* linkTo) const { - if (std::find(_inList.begin(), _inList.end(), linkTo) != _inList.end()) { + if (std::ranges::find(_inList, linkTo) != _inList.end()) { return true; } else { @@ -1253,7 +1253,7 @@ void App::DocumentObject::_removeBackLink(DocumentObject* rmvObj) { // do not use erase-remove idom, as this erases ALL entries that match. we only want to remove a // single one. - auto it = std::find(_inList.begin(), _inList.end(), rmvObj); + auto it = std::ranges::find(_inList, rmvObj); if (it != _inList.end()) { _inList.erase(it); } diff --git a/src/App/GeoFeatureGroupExtension.cpp b/src/App/GeoFeatureGroupExtension.cpp index c7bc8252e3..e1f1400dcb 100644 --- a/src/App/GeoFeatureGroupExtension.cpp +++ b/src/App/GeoFeatureGroupExtension.cpp @@ -338,7 +338,7 @@ void GeoFeatureGroupExtension::getCSInList(const DocumentObject* obj, // check if the link is real Local scope one or if it is a expression one (could also be // both, so it is not enough to check the expressions) auto res = getScopedObjectsFromLinks(parent, LinkScope::Local); - if (std::find(res.begin(), res.end(), obj) != res.end()) { + if (std::ranges::find(res, obj) != res.end()) { vec.push_back(parent); } } @@ -382,7 +382,7 @@ void GeoFeatureGroupExtension::recursiveCSRelevantLinks(const DocumentObject* ob // go on traversing the graph in all directions! for (auto o : links) { - if (!o || o == obj || std::find(vec.begin(), vec.end(), o) != vec.end()) { + if (!o || o == obj || std::ranges::find(vec, o) != vec.end()) { continue; } diff --git a/src/App/Graphviz.cpp b/src/App/Graphviz.cpp index f2765da4b3..9ab33c173b 100644 --- a/src/App/Graphviz.cpp +++ b/src/App/Graphviz.cpp @@ -290,7 +290,7 @@ void Document::exportGraphviz(std::ostream& out) const { // don't add objects twice - if (std::find(objects.begin(), objects.end(), docObj) != objects.end()) { + if (std::ranges::find(objects, docObj) != objects.end()) { return; } diff --git a/src/App/GroupExtension.cpp b/src/App/GroupExtension.cpp index ed10599419..8e1481310f 100644 --- a/src/App/GroupExtension.cpp +++ b/src/App/GroupExtension.cpp @@ -268,7 +268,7 @@ bool GroupExtension::recursiveHasObject(const DocumentObject* obj, auto ext = child->getExtensionByType(); - if (std::find(history.begin(), history.end(), ext) != history.end()) { + if (std::ranges::find(history, ext) != history.end()) { throw Base::RuntimeError( "Cyclic dependencies detected: Search cannot be performed"); } diff --git a/src/App/ProgramOptionsUtilities.h b/src/App/ProgramOptionsUtilities.h index cba3bcaf0b..5a511b0adc 100644 --- a/src/App/ProgramOptionsUtilities.h +++ b/src/App/ProgramOptionsUtilities.h @@ -74,7 +74,7 @@ std::pair customSyntax(std::string_view strIn) "title", "visual"}; - if (std::find(knowns.begin(), knowns.end(), rest) != knowns.end()) { + if (std::ranges::find(knowns, rest) != knowns.end()) { return {rest, "null"}; } return {}; diff --git a/src/App/PropertyExpressionEngine.cpp b/src/App/PropertyExpressionEngine.cpp index 7bc7182ee5..3f00faad18 100644 --- a/src/App/PropertyExpressionEngine.cpp +++ b/src/App/PropertyExpressionEngine.cpp @@ -1232,17 +1232,15 @@ void PropertyExpressionEngine::getLinksTo(std::vector& id identifiers.push_back(expressionId); break; } - if (std::any_of(paths.begin(), - paths.end(), - [subname, obj, sobj, &subElement](const auto& path) { - if (path.getSubObjectName() == subname) { - return true; - } + if (std::ranges::any_of(paths, [subname, obj, sobj, &subElement](const auto& path) { + if (path.getSubObjectName() == subname) { + return true; + } - App::SubObjectT sobjT(obj, path.getSubObjectName().c_str()); - return (sobjT.getSubObject() == sobj - && sobjT.getOldElementName() == subElement); - })) { + App::SubObjectT sobjT(obj, path.getSubObjectName().c_str()); + return (sobjT.getSubObject() == sobj + && sobjT.getOldElementName() == subElement); + })) { identifiers.push_back(expressionId); } }