C++11: replace deprecated function std::bind2nd with lambda functions

This commit is contained in:
wmayer
2020-10-15 14:46:02 +02:00
parent d8bbced84e
commit 56c6db10e0
11 changed files with 59 additions and 40 deletions

View File

@@ -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<Gui::ViewProvider*> Provider = getSelection();
std::vector<Gui::ViewProvider*>::const_iterator vp = std::find_if
(Provider.begin(), Provider.end(),
std::bind2nd(std::equal_to<Gui::ViewProvider*>(),
const_cast<Gui::ViewProvider*>(&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

View File

@@ -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<Gui::ViewProvider*> Provider = getSelection();
std::vector<Gui::ViewProvider*>::const_iterator vp = std::find_if
(Provider.begin(), Provider.end(),
std::bind2nd(std::equal_to<Gui::ViewProvider*>(),
const_cast<Gui::ViewProvider*>(&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())) {

View File

@@ -893,14 +893,16 @@ void MeshAlgorithm::ResetPointFlag (MeshPoint::TFlagType tF) const
unsigned long MeshAlgorithm::CountFacetFlag (MeshFacet::TFlagType tF) const
{
MeshIsFlag<MeshFacet> flag;
return std::count_if(_rclMesh._aclFacetArray.begin(), _rclMesh._aclFacetArray.end(),
std::bind2nd(MeshIsFlag<MeshFacet>(), tF));
[flag, tF](const MeshFacet& f) { return flag(f, tF);});
}
unsigned long MeshAlgorithm::CountPointFlag (MeshPoint::TFlagType tF) const
{
MeshIsFlag<MeshPoint> flag;
return std::count_if(_rclMesh._aclPointArray.begin(), _rclMesh._aclPointArray.end(),
std::bind2nd(MeshIsFlag<MeshPoint>(), tF));
[flag, tF](const MeshPoint& f) { return flag(f, tF);});
}
void MeshAlgorithm::GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, std::vector<unsigned long> &raclCutted ) const

View File

@@ -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<unsigned long>(), 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<unsigned long> 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<unsigned long>(), 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);
}

View File

@@ -226,7 +226,10 @@ std::vector<unsigned long> 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>(), MeshFacet::VISIT));
MeshIsNotFlag<MeshFacet> flag;
iTri = std::find_if(iTri, iEnd, [flag](const MeshFacet& f) {
return flag(f, MeshFacet::VISIT);
});
if (iTri < iEnd)
ulStartFacet = iTri - iBeg;

View File

@@ -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<std::string, int>& 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<std::string, int>& 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<std::string, int>& 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<std::string, int>& 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<std::string, int>& 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<std::string, int>& 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<MeshFacet> flag;
std::size_t countInvalidFacets = std::count_if(facetArray.begin(), facetArray.end(),
std::bind2nd(MeshIsFlag<MeshFacet>(), 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>(), MeshFacet::INVALID));
[flag](const MeshFacet& f) { return flag(f, MeshFacet::INVALID); });
facetArray.swap(copy_facets);
}
}
void MeshCleanup::RemoveInvalidPoints()
{
MeshIsFlag<MeshPoint> flag;
std::size_t countInvalidPoints = std::count_if(pointArray.begin(), pointArray.end(),
std::bind2nd(MeshIsFlag<MeshPoint>(), MeshPoint::INVALID));
[flag](const MeshPoint& p) { return flag(p, MeshPoint::INVALID); });
if (countInvalidPoints > 0) {
// generate array of decrements
std::vector<unsigned long> 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>(), MeshPoint::INVALID));
[flag](const MeshPoint& p) { return flag(p, MeshPoint::INVALID); });
pointArray.swap(copy_points);
}
}

View File

@@ -259,8 +259,10 @@ unsigned long MeshKernel::AddFacets(const std::vector<MeshFacet> &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>(), MeshFacet::INVALID));
MeshIsNotFlag<MeshFacet> 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<unsigned long>(), 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);

View File

@@ -556,8 +556,10 @@ void MeshSegmentAlgorithm::FindSegments(std::vector<MeshSurfaceSegmentPtr>& segm
cAlgo.ResetFacetsFlag(resetVisited, MeshCore::MeshFacet::VISIT);
resetVisited.clear();
iCur = std::find_if(iBeg, iEnd, std::bind2nd(MeshCore::MeshIsNotFlag<MeshCore::MeshFacet>(),
MeshCore::MeshFacet::VISIT));
MeshCore::MeshIsNotFlag<MeshCore::MeshFacet> 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<MeshSurfaceSegmentPtr>& segm
}
// search for the next start facet
iCur = std::find_if(iCur, iEnd, std::bind2nd(MeshCore::MeshIsNotFlag<MeshCore::MeshFacet>(),
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

View File

@@ -1587,7 +1587,10 @@ void MeshComponents::SearchForComponents(TMode tMode, const std::vector<unsigned
// start from the first not visited facet
ulVisited = cAlgo.CountFacetFlag(MeshFacet::VISIT);
iTri = std::find_if(iTri, iEnd, std::bind2nd(MeshIsNotFlag<MeshFacet>(), MeshFacet::VISIT));
MeshIsNotFlag<MeshFacet> 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<unsigned
// 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>(), MeshFacet::VISIT));
iTri = std::find_if(iTri, iEnd, [flag](const MeshFacet& f) {
return flag(f, MeshFacet::VISIT);
});
if (iTri < iEnd)
ulStartFacet = iTri - iBeg;

View File

@@ -685,8 +685,9 @@ void MeshObject::deletedFacets(const std::vector<unsigned long>& remFacets)
// remove the invalid indices
std::sort(segm.begin(), segm.end());
std::vector<unsigned long>::iterator ft = std::find_if
(segm.begin(), segm.end(),
std::bind2nd(std::equal_to<unsigned long>(), 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<unsigned long>& indic
pointDeg[face._aulPoints[2]]--;
}
unsigned long countInvalids = std::count_if(pointDeg.begin(), pointDeg.end(),
std::bind2nd(std::equal_to<unsigned long>(), 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<unsigned long>& 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<unsigned long>(), _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<std::pair<unsigned long, unsigned long> > selfIntersections;
std::vector<unsigned long>::const_iterator it;

View File

@@ -2047,9 +2047,10 @@ void ViewProviderMesh::invertSelection()
{
const Mesh::MeshObject& rMesh = static_cast<Mesh::Feature*>(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>(),
MeshCore::MeshFacet::SELECTED));
MeshCore::MeshIsNotFlag<MeshCore::MeshFacet> 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<unsigned long> notselect;
notselect.reserve(num_notsel);
MeshCore::MeshFacetArray::_TConstIterator beg = faces.begin();