Part: apply std::ranges

This commit is contained in:
bofdahof
2025-03-12 20:02:29 +10:00
committed by Chris Hennes
parent 216a76e971
commit 2ddd24bc6d
5 changed files with 27 additions and 34 deletions

View File

@@ -68,16 +68,12 @@ bool BodyBase::isAfter(const App::DocumentObject *feature, const App::DocumentOb
return hasObject (feature);
}
const std::vector<App::DocumentObject *> & features = Group.getValues();
auto featureIt = std::find(features.begin(), features.end(), feature);
auto targetIt = std::find(features.begin(), features.end(), target);
const std::vector<App::DocumentObject*>& features = Group.getValues();
const auto featureIt = std::ranges::find(features, feature);
const auto targetIt = std::ranges::find(features, target);
if (featureIt == features.end()) {
return false;
} else {
return featureIt > targetIt;
}
}
return featureIt == features.end() ? false : featureIt > targetIt;
}
void BodyBase::onBeforeChange (const App::Property* prop) {

View File

@@ -252,7 +252,7 @@ App::ElementNamePair Feature::getExportElementName(TopoShape shape,
}
else if (size > 1) {
for (auto it = ancestors.begin(); it != ancestors.end();) {
if (std::find(v.second.begin(), v.second.end(), *it)
if (std::ranges::find(v.second, *it)
== v.second.end()) {
it = ancestors.erase(it);
if (ancestors.size() == 1) {
@@ -283,13 +283,12 @@ App::ElementNamePair Feature::getExportElementName(TopoShape shape,
// The current chosen elements are not enough to
// identify the higher element, generate an index for
// disambiguation.
auto it = std::find(ancestors.begin(), ancestors.end(), res.second);
auto it = std::ranges::find(ancestors, res.second);
if (it == ancestors.end()) {
assert(0 && "ancestor not found"); // this shouldn't happen
}
else {
op = Data::POSTFIX_INDEX + std::to_string(it - ancestors.begin());
}
op = Data::POSTFIX_INDEX + std::to_string(it - ancestors.begin());
}
// Note: setting names to shape will change its underlying
@@ -367,7 +366,7 @@ App::ElementNamePair Feature::getExportElementName(TopoShape shape,
}
else {
for (auto it = ancestors.begin(); it != ancestors.end();) {
if (std::find(current.begin(), current.end(), *it) == current.end()) {
if (std::ranges::find(current, *it) == current.end()) {
it = ancestors.erase(it);
}
else {

View File

@@ -291,13 +291,13 @@ public:
bool contains(const T &vForContains)
{
if (!sorted) {
const size_t dataSizeMax = 30;
constexpr static size_t dataSizeMax = 30;
if (data.size() < dataSizeMax) {
return std::find(data.begin(), data.end(), vForContains) != data.end();
return std::ranges::find(data, vForContains) != data.end();
}
sort();
}
auto it = std::lower_bound(data.begin(), data.end(), vForContains);
auto it = std::ranges::lower_bound(data, vForContains);
return it!=data.end() && *it == vForContains;
}
bool intersects(const VectorSet<T> &other)
@@ -330,7 +330,7 @@ public:
void insert(const T &vToInsert)
{
if (sorted) {
data.insert(std::upper_bound(data.begin(), data.end(), vToInsert), vToInsert);
data.insert(std::ranges::upper_bound(data, vToInsert), vToInsert);
}
else {
data.push_back(vToInsert);
@@ -339,7 +339,7 @@ public:
bool insertUnique(const T &vToInsertUnique)
{
if (sorted) {
auto it = std::lower_bound(data.begin(), data.end(), vToInsertUnique);
auto it = std::ranges::lower_bound(data, vToInsertUnique);
bool insert = !(it != data.end() && *it == vToInsertUnique);
if (insert) {
data.insert(it, vToInsertUnique);
@@ -359,7 +359,7 @@ public:
data.erase(std::remove(data.begin(), data.end(), vToErase), data.end());
}
else {
auto it = std::lower_bound(data.begin(), data.end(), vToErase);
auto it = std::ranges::lower_bound(data, vToErase);
auto itEnd = it;
while (itEnd != data.end() && *itEnd == vToErase) {
++itEnd;
@@ -493,15 +493,15 @@ public:
{
const size_t verticesSizeMax = 20;
if (vertices.size() < verticesSizeMax) {
auto it = std::find(vertices.begin(), vertices.end(), info);
const auto it = std::ranges::find(vertices, info);
if (it == vertices.end()) {
return 0;
}
return (static_cast<int>(it - vertices.begin()) + 1);
}
sort();
auto it = std::lower_bound(sorted.begin(), sorted.end(), info,
[&](int idx, const VertexInfo &vertex) {return vertices[idx]<vertex;});
const auto it = std::lower_bound(sorted.begin(), sorted.end(), info,
[&](const int idx, const VertexInfo &vertex) {return vertices[idx]<vertex;});
int res = 0;
if (it != sorted.end() && vertices[*it] == info) {
res = *it + 1;
@@ -520,7 +520,7 @@ public:
return 0;
}
sort();
auto it = std::lower_bound(sorted.begin(), sorted.end(), info,
const auto it = std::lower_bound(sorted.begin(), sorted.end(), info,
[&](int idx, const EdgeInfo *vertex) {return vertices[idx].edgeInfo()<vertex;});
int res = 0;
if (it != sorted.end() && vertices[*it].edgeInfo() == info) {

View File

@@ -134,9 +134,8 @@ void DlgBooleanOperation::slotCreatedObject(const App::DocumentObject& obj)
void DlgBooleanOperation::slotChangedObject(const App::DocumentObject& obj,
const App::Property& prop)
{
std::list<const App::DocumentObject*>::iterator it;
it = std::find(observe.begin(), observe.end(), &obj);
if (it != observe.end() && prop.is<Part::PropertyPartShape>()) {
if (const auto it = std::ranges::find(observe, &obj);
it != observe.end() && prop.is<Part::PropertyPartShape>()) {
const TopoDS_Shape& shape = static_cast<const Part::PropertyPartShape&>(prop).getValue();
if (!shape.IsNull()) {
Gui::Document* activeGui = Gui::Application::Instance->getDocument(obj.getDocument());

View File

@@ -605,10 +605,9 @@ void DlgFilletEdges::setupFillet(const std::vector<App::DocumentObject*>& objs)
for(auto &sub : subs)
subSet.insert(sub.newName.empty()?sub.oldName:sub.newName);
std::string tmp;
std::vector<App::DocumentObject*>::const_iterator it = std::find(objs.begin(), objs.end(), base);
if (it != objs.end()) {
if (auto it = std::ranges::find(objs, base); it != objs.end()) {
// toggle visibility
std::string tmp;
Gui::ViewProvider* vp;
vp = Gui::Application::Instance->getViewProvider(d->fillet);
if (vp) vp->hide();
@@ -662,9 +661,9 @@ void DlgFilletEdges::setupFillet(const std::vector<App::DocumentObject*>& objs)
}
for (const auto & et : e) {
std::vector<int>::iterator it = std::find(d->edge_ids.begin(), d->edge_ids.end(), et.edgeid);
if (it != d->edge_ids.end()) {
int index = it - d->edge_ids.begin();
auto it2 = std::ranges::find(d->edge_ids, et.edgeid);
if (it2 != d->edge_ids.end()) {
int index = it2 - d->edge_ids.begin();
model->setData(model->index(index, 0), Qt::Checked, Qt::CheckStateRole);
//model->setData(model->index(index, 1), QVariant(QLocale().toString(et->radius1,'f',Base::UnitsApi::getDecimals())));
//model->setData(model->index(index, 2), QVariant(QLocale().toString(et->radius2,'f',Base::UnitsApi::getDecimals())));