From 7ad4641e79169e297a88ee9e62e9be3d74f7124e Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Sat, 18 Nov 2023 21:22:57 +0100 Subject: [PATCH] c++20: use std::erase(_if) instead of std::remove(_if)+erase (part 8) Change-Id: Ia726fbbfd3f08eb4bb5c7ccaf10d65fe01ca6585 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159639 Tested-by: Jenkins Reviewed-by: Julien Nabet --- sc/source/core/data/dpobject.cxx | 4 ++-- sc/source/core/data/dpsave.cxx | 4 ++-- sc/source/core/tool/dbdata.cxx | 2 +- sc/source/core/tool/detdata.cxx | 5 ++--- sc/source/core/tool/rangelst.cxx | 5 ++--- sc/source/filter/inc/xerecord.hxx | 4 +--- sc/source/filter/xml/xmlcondformat.cxx | 4 +--- sc/source/ui/docshell/macromgr.cxx | 2 +- sc/source/ui/unoobj/viewuno.cxx | 8 ++------ sc/source/ui/view/gridwin.cxx | 2 +- 10 files changed, 15 insertions(+), 25 deletions(-) diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 8c549ed4b3ab..37a7bf73d35a 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -3627,7 +3627,7 @@ bool ScDPCollection::GetReferenceGroups(const ScDPObject& rDPObj, const ScDPDime void ScDPCollection::DeleteOnTab( SCTAB nTab ) { - maTables.erase( std::remove_if(maTables.begin(), maTables.end(), MatchByTable(nTab)), maTables.end()); + std::erase_if(maTables, MatchByTable(nTab)); } void ScDPCollection::UpdateReference( UpdateRefMode eUpdateRefMode, @@ -3765,7 +3765,7 @@ void ScDPCollection::FreeTable(const ScDPObject* pDPObject) return pCurrent.get() == pDPObject; }; - maTables.erase(std::remove_if(maTables.begin(), maTables.end(), funcRemoveCondition), maTables.end()); + std::erase_if(maTables, funcRemoveCondition); } ScDPObject* ScDPCollection::InsertNewTable(std::unique_ptr pDPObj) diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx index 74f9131caf16..246714e84321 100644 --- a/sc/source/core/data/dpsave.cxx +++ b/sc/source/core/data/dpsave.cxx @@ -302,7 +302,7 @@ void ScDPSaveDimension::AddMember(std::unique_ptr pMember) } else { - maMemberList.erase(std::remove(maMemberList.begin(), maMemberList.end(), aExisting->second.get()), maMemberList.end()); + std::erase(maMemberList, aExisting->second.get()); aExisting->second = std::move(pMember); } maMemberList.push_back( tmp ); @@ -471,7 +471,7 @@ void ScDPSaveDimension::SetMemberPosition( const OUString& rName, sal_Int32 nNew { ScDPSaveMember* pMember = GetMemberByName( rName ); // make sure it exists and is in the hash - maMemberList.erase(std::remove( maMemberList.begin(), maMemberList.end(), pMember), maMemberList.end() ); + std::erase(maMemberList, pMember); maMemberList.insert( maMemberList.begin() + nNewPos, pMember ); } diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx index 69e28ca62876..c2096b39c4d1 100644 --- a/sc/source/core/tool/dbdata.cxx +++ b/sc/source/core/tool/dbdata.cxx @@ -1329,7 +1329,7 @@ const ScDBData* ScDBCollection::AnonDBs::findByRange(const ScRange& rRange) cons void ScDBCollection::AnonDBs::deleteOnTab(SCTAB nTab) { FindByTable func(nTab); - m_DBs.erase(std::remove_if(m_DBs.begin(), m_DBs.end(), func), m_DBs.end()); + std::erase_if(m_DBs, func); } ScDBData* ScDBCollection::AnonDBs::getByRange(const ScRange& rRange) diff --git a/sc/source/core/tool/detdata.cxx b/sc/source/core/tool/detdata.cxx index 6faa3cb37c0d..8af4e0bf0c53 100644 --- a/sc/source/core/tool/detdata.cxx +++ b/sc/source/core/tool/detdata.cxx @@ -29,11 +29,10 @@ ScDetOpList::ScDetOpList(const ScDetOpList& rList) : void ScDetOpList::DeleteOnTab( SCTAB nTab ) { - aDetOpDataVector.erase(std::remove_if(aDetOpDataVector.begin(), aDetOpDataVector.end(), + std::erase_if(aDetOpDataVector, [&nTab](const ScDetOpData& rxDetOpData) { return rxDetOpData.GetPos().Tab() == nTab; // look for operations on the deleted sheet - }), - aDetOpDataVector.end()); + }); } void ScDetOpList::UpdateReference( const ScDocument* pDoc, UpdateRefMode eUpdateRefMode, diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx index fb880d308c89..f84c92c7a7ae 100644 --- a/sc/source/core/tool/rangelst.cxx +++ b/sc/source/core/tool/rangelst.cxx @@ -1268,12 +1268,11 @@ void ScRangePairList::UpdateReference( UpdateRefMode eUpdateRefMode, // Delete entries that have the labels (first range) on nTab void ScRangePairList::DeleteOnTab( SCTAB nTab ) { - maPairs.erase(std::remove_if(maPairs.begin(), maPairs.end(), + std::erase_if(maPairs, [&nTab](const ScRangePair& rR) { const ScRange & rRange = rR.GetRange(0); return (rRange.aStart.Tab() == nTab) && (rRange.aEnd.Tab() == nTab); - }), - maPairs.end()); + }); } ScRangePair* ScRangePairList::Find( const ScAddress& rAdr ) diff --git a/sc/source/filter/inc/xerecord.hxx b/sc/source/filter/inc/xerecord.hxx index c6901e7fb022..a05ea97cbb41 100644 --- a/sc/source/filter/inc/xerecord.hxx +++ b/sc/source/filter/inc/xerecord.hxx @@ -395,9 +395,7 @@ public: void InvalidateRecord( size_t nPos ) { maRecs[ nPos ] = nullptr; } void RemoveInvalidatedRecords() { - maRecs.erase( - std::remove_if( maRecs.begin(), maRecs.end(), [](const RecordRefType& xRec) { return xRec == nullptr; } ), - maRecs.end()); + std::erase_if(maRecs, [](const RecordRefType& xRec) { return xRec == nullptr; } ); } private: diff --git a/sc/source/filter/xml/xmlcondformat.cxx b/sc/source/filter/xml/xmlcondformat.cxx index 77280be47e21..23127414a164 100644 --- a/sc/source/filter/xml/xmlcondformat.cxx +++ b/sc/source/filter/xml/xmlcondformat.cxx @@ -54,9 +54,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL ScXMLConditio IMPL_LINK(ScXMLConditionalFormatsContext, FormatDeletedHdl, ScConditionalFormat*, pFormat, void) { - mvCondFormatData.erase(std::remove_if(mvCondFormatData.begin(), mvCondFormatData.end(), - [pFormat](CondFormatData& r){ return r.mpFormat == pFormat; }), - mvCondFormatData.end()); + std::erase_if(mvCondFormatData, [pFormat](CondFormatData& r){ return r.mpFormat == pFormat; }); } void SAL_CALL ScXMLConditionalFormatsContext::endFastElement( sal_Int32 /*nElement*/ ) diff --git a/sc/source/ui/docshell/macromgr.cxx b/sc/source/ui/docshell/macromgr.cxx index 9850b4ce90d2..455571e7917c 100644 --- a/sc/source/ui/docshell/macromgr.cxx +++ b/sc/source/ui/docshell/macromgr.cxx @@ -63,7 +63,7 @@ public: { for (auto& rEntry : maCells) { - rEntry.second.erase(std::remove(rEntry.second.begin(), rEntry.second.end(), pCell), rEntry.second.end() ); + std::erase(rEntry.second, pCell); } } diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx index e9b6c31fe70b..9304d72471d9 100644 --- a/sc/source/ui/unoobj/viewuno.cxx +++ b/sc/source/ui/unoobj/viewuno.cxx @@ -1343,9 +1343,7 @@ void SAL_CALL ScTabViewObj::removeEnhancedMouseClickHandler( const uno::Referenc { SolarMutexGuard aGuard; sal_uInt16 nCount = aMouseClickHandlers.size(); - aMouseClickHandlers.erase( - std::remove(aMouseClickHandlers.begin(), aMouseClickHandlers.end(), aListener), - aMouseClickHandlers.end()); + std::erase(aMouseClickHandlers, aListener); if (aMouseClickHandlers.empty() && (nCount > 0)) // only if last listener removed EndMouseListening(); } @@ -1366,9 +1364,7 @@ void SAL_CALL ScTabViewObj::removeActivationEventListener( const uno::Reference< { SolarMutexGuard aGuard; sal_uInt16 nCount = aActivationListeners.size(); - aActivationListeners.erase( - std::remove(aActivationListeners.begin(), aActivationListeners.end(), aListener), - aActivationListeners.end()); + std::erase(aActivationListeners, aListener); if (aActivationListeners.empty() && (nCount > 0)) // only if last listener removed EndActivationListening(); } diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index ffd6362ab584..557e78ea991a 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -1542,7 +1542,7 @@ void ScGridWindow::LaunchDataSelectMenu(const SCCOL nCol, const SCROW nRow) if (pData && !pData->IsIgnoreBlank()) { auto lambda = [](const ScTypedStrData& rStr) { return rStr.GetString().isEmpty(); }; - aStrings.erase(std::remove_if(aStrings.begin(), aStrings.end(), lambda), aStrings.end()); + std::erase_if(aStrings, lambda); } if (aStrings.empty())