From 56c6db10e015f9eb84af2d3c8ebddb43afa9eea1 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 15 Oct 2020 14:46:02 +0200 Subject: [PATCH] C++11: replace deprecated function std::bind2nd with lambda functions --- src/Gui/DlgDisplayPropertiesImp.cpp | 5 ++--- src/Gui/TaskView/TaskAppearance.cpp | 5 ++--- src/Mod/Mesh/App/Core/Algorithm.cpp | 6 ++++-- src/Mod/Mesh/App/Core/Degeneration.cpp | 4 ++-- src/Mod/Mesh/App/Core/Evaluation.cpp | 5 ++++- src/Mod/Mesh/App/Core/MeshIO.cpp | 22 ++++++++++++---------- src/Mod/Mesh/App/Core/MeshKernel.cpp | 11 +++++++---- src/Mod/Mesh/App/Core/Segmentation.cpp | 11 +++++++---- src/Mod/Mesh/App/Core/TopoAlgorithm.cpp | 9 +++++++-- src/Mod/Mesh/App/Mesh.cpp | 14 ++++++++------ src/Mod/Mesh/Gui/ViewProvider.cpp | 7 ++++--- 11 files changed, 59 insertions(+), 40 deletions(-) diff --git a/src/Gui/DlgDisplayPropertiesImp.cpp b/src/Gui/DlgDisplayPropertiesImp.cpp index a65b5bad5f..c84eb5d3b4 100644 --- a/src/Gui/DlgDisplayPropertiesImp.cpp +++ b/src/Gui/DlgDisplayPropertiesImp.cpp @@ -168,9 +168,8 @@ void DlgDisplayPropertiesImp::slotChangedObject(const Gui::ViewProvider& obj, // We pick out all the properties for which we need to update this dialog. std::vector Provider = getSelection(); std::vector::const_iterator vp = std::find_if - (Provider.begin(), Provider.end(), - std::bind2nd(std::equal_to(), - const_cast(&obj))); + (Provider.begin(), Provider.end(), [&obj](Gui::ViewProvider* v) { return v == &obj; }); + if (vp != Provider.end()) { const char* name = obj.getPropertyName(&prop); // this is not a property of the view provider but of the document object diff --git a/src/Gui/TaskView/TaskAppearance.cpp b/src/Gui/TaskView/TaskAppearance.cpp index 08b09fa623..10b034f067 100644 --- a/src/Gui/TaskView/TaskAppearance.cpp +++ b/src/Gui/TaskView/TaskAppearance.cpp @@ -101,9 +101,8 @@ void TaskAppearance::slotChangedObject(const Gui::ViewProvider& obj, // We pick out all the properties for which we need to update this dialog. std::vector Provider = getSelection(); std::vector::const_iterator vp = std::find_if - (Provider.begin(), Provider.end(), - std::bind2nd(std::equal_to(), - const_cast(&obj))); + (Provider.begin(), Provider.end(), [&obj](Gui::ViewProvider* v) { return v == &obj; }); + if (vp != Provider.end()) { std::string prop_name = obj.getPropertyName(&prop); if (prop.getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())) { diff --git a/src/Mod/Mesh/App/Core/Algorithm.cpp b/src/Mod/Mesh/App/Core/Algorithm.cpp index 40d7727dbc..bc58c6e6cf 100644 --- a/src/Mod/Mesh/App/Core/Algorithm.cpp +++ b/src/Mod/Mesh/App/Core/Algorithm.cpp @@ -893,14 +893,16 @@ void MeshAlgorithm::ResetPointFlag (MeshPoint::TFlagType tF) const unsigned long MeshAlgorithm::CountFacetFlag (MeshFacet::TFlagType tF) const { + MeshIsFlag flag; return std::count_if(_rclMesh._aclFacetArray.begin(), _rclMesh._aclFacetArray.end(), - std::bind2nd(MeshIsFlag(), tF)); + [flag, tF](const MeshFacet& f) { return flag(f, tF);}); } unsigned long MeshAlgorithm::CountPointFlag (MeshPoint::TFlagType tF) const { + MeshIsFlag flag; return std::count_if(_rclMesh._aclPointArray.begin(), _rclMesh._aclPointArray.end(), - std::bind2nd(MeshIsFlag(), tF)); + [flag, tF](const MeshPoint& f) { return flag(f, tF);}); } void MeshAlgorithm::GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, std::vector &raclCutted ) const diff --git a/src/Mod/Mesh/App/Core/Degeneration.cpp b/src/Mod/Mesh/App/Core/Degeneration.cpp index 6b09730d72..440fb0bdeb 100644 --- a/src/Mod/Mesh/App/Core/Degeneration.cpp +++ b/src/Mod/Mesh/App/Core/Degeneration.cpp @@ -1158,7 +1158,7 @@ bool MeshEvalRangePoint::Evaluate() unsigned long ulCtPoints = _rclMesh.CountPoints(); for (MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it) { - if (std::find_if(it->_aulPoints, it->_aulPoints + 3, std::bind2nd(std::greater_equal(), ulCtPoints)) < it->_aulPoints + 3) + if (std::find_if(it->_aulPoints, it->_aulPoints + 3, [ulCtPoints](unsigned long i) { return i >= ulCtPoints; }) < it->_aulPoints + 3) return false; } @@ -1173,7 +1173,7 @@ std::vector MeshEvalRangePoint::GetIndices() const unsigned long ind=0; for (MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it, ind++) { - if (std::find_if(it->_aulPoints, it->_aulPoints + 3, std::bind2nd(std::greater_equal(), ulCtPoints)) < it->_aulPoints + 3) + if (std::find_if(it->_aulPoints, it->_aulPoints + 3, [ulCtPoints](unsigned long i) { return i >= ulCtPoints; }) < it->_aulPoints + 3) aInds.push_back(ind); } diff --git a/src/Mod/Mesh/App/Core/Evaluation.cpp b/src/Mod/Mesh/App/Core/Evaluation.cpp index 23e0afb0df..440e538fd3 100644 --- a/src/Mod/Mesh/App/Core/Evaluation.cpp +++ b/src/Mod/Mesh/App/Core/Evaluation.cpp @@ -226,7 +226,10 @@ std::vector MeshEvalOrientation::GetIndices() const // if the mesh consists of several topologic independent components // We can search from position 'iTri' on because all elements _before_ are already visited // what we know from the previous iteration. - iTri = std::find_if(iTri, iEnd, std::bind2nd(MeshIsNotFlag(), MeshFacet::VISIT)); + MeshIsNotFlag flag; + iTri = std::find_if(iTri, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); if (iTri < iEnd) ulStartFacet = iTri - iBeg; diff --git a/src/Mod/Mesh/App/Core/MeshIO.cpp b/src/Mod/Mesh/App/Core/MeshIO.cpp index 4cd066e5e7..bd8c5597ef 100644 --- a/src/Mod/Mesh/App/Core/MeshIO.cpp +++ b/src/Mod/Mesh/App/Core/MeshIO.cpp @@ -967,17 +967,17 @@ bool MeshInput::LoadPLY (std::istream &inp) // check if valid 3d points Property property; std::size_t num_x = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "x")); + [&property](const std::pair& p) { return property(p, "x"); }); if (num_x != 1) return false; std::size_t num_y = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "y")); + [&property](const std::pair& p) { return property(p, "y"); }); if (num_y != 1) return false; std::size_t num_z = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "z")); + [&property](const std::pair& p) { return property(p, "z"); }); if (num_z != 1) return false; @@ -993,11 +993,11 @@ bool MeshInput::LoadPLY (std::istream &inp) // check if valid colors are set std::size_t num_r = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "red")); + [&property](const std::pair& p) { return property(p, "red"); }); std::size_t num_g = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "green")); + [&property](const std::pair& p) { return property(p, "green"); }); std::size_t num_b = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "blue")); + [&property](const std::pair& p) { return property(p, "blue"); }); std::size_t rgb_colors = num_r + num_g + num_b; if (rgb_colors != 0 && rgb_colors != 3) return false; @@ -3501,8 +3501,9 @@ void MeshCleanup::RemoveInvalids() void MeshCleanup::RemoveInvalidFacets() { + MeshIsFlag flag; std::size_t countInvalidFacets = std::count_if(facetArray.begin(), facetArray.end(), - std::bind2nd(MeshIsFlag(), MeshFacet::INVALID)); + [flag](const MeshFacet& f) { return flag(f, MeshFacet::INVALID); }); if (countInvalidFacets > 0) { // adjust the material array if needed @@ -3522,15 +3523,16 @@ void MeshCleanup::RemoveInvalidFacets() MeshFacetArray copy_facets(facetArray.size() - countInvalidFacets); // copy all valid facets to the new array std::remove_copy_if(facetArray.begin(), facetArray.end(), copy_facets.begin(), - std::bind2nd(MeshIsFlag(), MeshFacet::INVALID)); + [flag](const MeshFacet& f) { return flag(f, MeshFacet::INVALID); }); facetArray.swap(copy_facets); } } void MeshCleanup::RemoveInvalidPoints() { + MeshIsFlag flag; std::size_t countInvalidPoints = std::count_if(pointArray.begin(), pointArray.end(), - std::bind2nd(MeshIsFlag(), MeshPoint::INVALID)); + [flag](const MeshPoint& p) { return flag(p, MeshPoint::INVALID); }); if (countInvalidPoints > 0) { // generate array of decrements std::vector decrements; @@ -3573,7 +3575,7 @@ void MeshCleanup::RemoveInvalidPoints() MeshPointArray copy_points(validPoints); // copy all valid facets to the new array std::remove_copy_if(pointArray.begin(), pointArray.end(), copy_points.begin(), - std::bind2nd(MeshIsFlag(), MeshPoint::INVALID)); + [flag](const MeshPoint& p) { return flag(p, MeshPoint::INVALID); }); pointArray.swap(copy_points); } } diff --git a/src/Mod/Mesh/App/Core/MeshKernel.cpp b/src/Mod/Mesh/App/Core/MeshKernel.cpp index c73e2314b8..34ef5f2c5d 100644 --- a/src/Mod/Mesh/App/Core/MeshKernel.cpp +++ b/src/Mod/Mesh/App/Core/MeshKernel.cpp @@ -259,8 +259,10 @@ unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, // Do not insert directly to the data structure because we should get the correct size of new // facets, otherwise std::vector reallocates too much memory which can't be freed so easily - unsigned long countValid = std::count_if(rclFAry.begin(), rclFAry.end(), - std::bind2nd(MeshIsNotFlag(), MeshFacet::INVALID)); + MeshIsNotFlag flag; + unsigned long countValid = std::count_if(rclFAry.begin(), rclFAry.end(), [flag](const MeshFacet& f) { + return flag(f, MeshFacet::INVALID); + }); _aclFacetArray.reserve( _aclFacetArray.size() + countValid ); // now start inserting the facets to the data structure and set the correct neighbourhood as well unsigned long startIndex = CountFacets(); @@ -374,8 +376,9 @@ void MeshKernel::Merge(const MeshPointArray& rPoints, const MeshFacetArray& rFac this->_aclFacetArray.push_back(face); } - unsigned long countNewPoints = std::count_if(increments.begin(), increments.end(), - std::bind2nd(std::greater(), 0)); + unsigned long countNewPoints = std::count_if(increments.begin(), increments.end(),[](unsigned long v) { + return v > 0; + }); // Reserve the additional memory to append the new points unsigned long index = this->_aclPointArray.size(); this->_aclPointArray.reserve(this->_aclPointArray.size() + countNewPoints); diff --git a/src/Mod/Mesh/App/Core/Segmentation.cpp b/src/Mod/Mesh/App/Core/Segmentation.cpp index 1e6e6eefb5..5e84f92ba4 100644 --- a/src/Mod/Mesh/App/Core/Segmentation.cpp +++ b/src/Mod/Mesh/App/Core/Segmentation.cpp @@ -556,8 +556,10 @@ void MeshSegmentAlgorithm::FindSegments(std::vector& segm cAlgo.ResetFacetsFlag(resetVisited, MeshCore::MeshFacet::VISIT); resetVisited.clear(); - iCur = std::find_if(iBeg, iEnd, std::bind2nd(MeshCore::MeshIsNotFlag(), - MeshCore::MeshFacet::VISIT)); + MeshCore::MeshIsNotFlag flag; + iCur = std::find_if(iBeg, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); if (iCur < iEnd) startFacet = iCur - iBeg; else @@ -580,8 +582,9 @@ void MeshSegmentAlgorithm::FindSegments(std::vector& segm } // search for the next start facet - iCur = std::find_if(iCur, iEnd, std::bind2nd(MeshCore::MeshIsNotFlag(), - MeshCore::MeshFacet::VISIT)); + iCur = std::find_if(iCur, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); if (iCur < iEnd) startFacet = iCur - iBeg; else diff --git a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp index 1f598fabdc..830a18a327 100644 --- a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp +++ b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp @@ -1587,7 +1587,10 @@ void MeshComponents::SearchForComponents(TMode tMode, const std::vector(), MeshFacet::VISIT)); + MeshIsNotFlag flag; + iTri = std::find_if(iTri, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); ulStartFacet = iTri - iBeg; // visitor @@ -1611,7 +1614,9 @@ void MeshComponents::SearchForComponents(TMode tMode, const std::vector(), MeshFacet::VISIT)); + iTri = std::find_if(iTri, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); if (iTri < iEnd) ulStartFacet = iTri - iBeg; diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index de8d7cb083..f3347c8b32 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -685,8 +685,9 @@ void MeshObject::deletedFacets(const std::vector& remFacets) // remove the invalid indices std::sort(segm.begin(), segm.end()); std::vector::iterator ft = std::find_if - (segm.begin(), segm.end(), - std::bind2nd(std::equal_to(), ULONG_MAX)); + (segm.begin(), segm.end(), [](unsigned long v) { + return v == ULONG_MAX; + }); if (ft != segm.end()) segm.erase(ft, segm.end()); it->_indices = segm; @@ -839,8 +840,9 @@ unsigned long MeshObject::getPointDegree(const std::vector& indic pointDeg[face._aulPoints[2]]--; } - unsigned long countInvalids = std::count_if(pointDeg.begin(), pointDeg.end(), - std::bind2nd(std::equal_to(), 0)); + unsigned long countInvalids = std::count_if(pointDeg.begin(), pointDeg.end(), [](unsigned long v) { + return v == 0; + }); point_degree.swap(pointDeg); return countInvalids; @@ -1386,8 +1388,8 @@ void MeshObject::removeSelfIntersections(const std::vector& indic // make sure that the number of indices is even and are in range if (indices.size() % 2 != 0) return; - if (std::find_if(indices.begin(), indices.end(), - std::bind2nd(std::greater_equal(), _kernel.CountFacets())) < indices.end()) + unsigned long cntfacets = _kernel.CountFacets(); + if (std::find_if(indices.begin(), indices.end(), [cntfacets](unsigned long v) { return v >= cntfacets; }) < indices.end()) return; std::vector > selfIntersections; std::vector::const_iterator it; diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index c288568a4d..8e7601dd48 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -2047,9 +2047,10 @@ void ViewProviderMesh::invertSelection() { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); const MeshCore::MeshFacetArray& faces = rMesh.getKernel().GetFacets(); - unsigned long num_notsel = std::count_if(faces.begin(), faces.end(), - std::bind2nd(MeshCore::MeshIsNotFlag(), - MeshCore::MeshFacet::SELECTED)); + MeshCore::MeshIsNotFlag flag; + unsigned long num_notsel = std::count_if(faces.begin(), faces.end(), [flag](const MeshCore::MeshFacet& f) { + return flag(f, MeshCore::MeshFacet::SELECTED); + }); std::vector notselect; notselect.reserve(num_notsel); MeshCore::MeshFacetArray::_TConstIterator beg = faces.begin();