diff options
Diffstat (limited to 'sc/source/core')
24 files changed, 153 insertions, 260 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 594ad8acf8bc..51e0ea4ec813 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -2340,10 +2340,9 @@ public: virtual size_t Marshal( cl_kernel k, int argno, int nVectorWidth, cl_program pProgram ) override { unsigned i = 0; - for (SubArgumentsType::iterator it = mvSubArguments.begin(), e = mvSubArguments.end(); it != e; - ++it) + for (const auto& rxSubArgument : mvSubArguments) { - i += (*it)->Marshal(k, argno + i, nVectorWidth, pProgram); + i += rxSubArgument->Marshal(k, argno + i, nVectorWidth, pProgram); } if (dynamic_cast<OpGeoMean*>(mpCodeGen.get())) { @@ -2353,10 +2352,9 @@ public: cl_mem pClmem2; std::vector<cl_mem> vclmem; - for (SubArgumentsType::iterator it = mvSubArguments.begin(), - e = mvSubArguments.end(); it != e; ++it) + for (const auto& rxSubArgument : mvSubArguments) { - if (VectorRef* VR = dynamic_cast<VectorRef*>(it->get())) + if (VectorRef* VR = dynamic_cast<VectorRef*>(rxSubArgument.get())) vclmem.push_back(VR->GetCLBuffer()); else vclmem.push_back(nullptr); @@ -2422,12 +2420,11 @@ public: size_t nCurWindowSize = slidingArgPtr->GetWindowSize(); std::vector<SumIfsArgs> vclmem; - for (SubArgumentsType::iterator it = mvSubArguments.begin(), - e = mvSubArguments.end(); it != e; ++it) + for (const auto& rxSubArgument : mvSubArguments) { - if (VectorRef* VR = dynamic_cast<VectorRef*>(it->get())) + if (VectorRef* VR = dynamic_cast<VectorRef*>(rxSubArgument.get())) vclmem.emplace_back(VR->GetCLBuffer()); - else if (DynamicKernelConstantArgument* CA = dynamic_cast<DynamicKernelConstantArgument*>(it->get())) + else if (DynamicKernelConstantArgument* CA = dynamic_cast<DynamicKernelConstantArgument*>(rxSubArgument.get())) vclmem.emplace_back(CA->GetDouble()); else vclmem.emplace_back(nullptr); @@ -3880,16 +3877,14 @@ void DynamicKernel::CodeGen() // preambles decl << publicFunc; DK->DumpInlineFun(inlineDecl, inlineFun); - for (std::set<std::string>::iterator set_iter = inlineDecl.begin(); - set_iter != inlineDecl.end(); ++set_iter) + for (const auto& rItem : inlineDecl) { - decl << *set_iter; + decl << rItem; } - for (std::set<std::string>::iterator set_iter = inlineFun.begin(); - set_iter != inlineFun.end(); ++set_iter) + for (const auto& rItem : inlineFun) { - decl << *set_iter; + decl << rItem; } mSyms.DumpSlidingWindowFunctions(decl); mKernelSignature = DK->DumpOpName(); diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx index 2ce4acabac43..75c2cf21e015 100644 --- a/sc/source/core/tool/addincol.cxx +++ b/sc/source/core/tool/addincol.cxx @@ -150,14 +150,12 @@ bool ScUnoAddInFuncData::GetExcelName( LanguageType eDestLang, OUString& rRetExc const OUString& aSearch( aLanguageTag.getBcp47()); // First, check exact match without fallback overhead. - ::std::vector<LocalizedName>::const_iterator itNames( rCompNames.begin()); - for ( ; itNames != rCompNames.end(); ++itNames) + ::std::vector<LocalizedName>::const_iterator itNames = std::find_if(rCompNames.begin(), rCompNames.end(), + [&aSearch](const LocalizedName& rName) { return rName.maLocale == aSearch; }); + if (itNames != rCompNames.end()) { - if ((*itNames).maLocale == aSearch) - { - rRetExcelName = (*itNames).maName; - return true; - } + rRetExcelName = (*itNames).maName; + return true; } // Second, try match of fallback search with fallback locales, @@ -171,22 +169,16 @@ bool ScUnoAddInFuncData::GetExcelName( LanguageType eDestLang, OUString& rRetExc aFallbackSearch.emplace_back("en"); } } - ::std::vector< OUString >::const_iterator itSearch( aFallbackSearch.begin()); - for ( ; itSearch != aFallbackSearch.end(); ++itSearch) + for (const auto& rSearch : aFallbackSearch) { - itNames = rCompNames.begin(); - for ( ; itNames != rCompNames.end(); ++itNames) + for (const auto& rCompName : rCompNames) { // We checked already the full tag, start with second. - ::std::vector< OUString > aFallbackLocales( LanguageTag( (*itNames).maLocale).getFallbackStrings( false)); - for (::std::vector< OUString >::const_iterator itLocales( aFallbackLocales.begin()); - itLocales != aFallbackLocales.end(); ++itLocales) + ::std::vector< OUString > aFallbackLocales( LanguageTag( rCompName.maLocale).getFallbackStrings( false)); + if (std::find(aFallbackLocales.begin(), aFallbackLocales.end(), rSearch) != aFallbackLocales.end()) { - if (*itLocales == *itSearch) - { - rRetExcelName = (*itNames).maName; - return true; - } + rRetExcelName = rCompName.maName; + return true; } } } @@ -605,17 +597,16 @@ bool ScUnoAddInCollection::GetCalcName( const OUString& rExcelName, OUString& rR if ( pFuncData ) { const ::std::vector<ScUnoAddInFuncData::LocalizedName>& rNames = pFuncData->GetCompNames(); - ::std::vector<ScUnoAddInFuncData::LocalizedName>::const_iterator it( rNames.begin()); - for ( ; it != rNames.end(); ++it) + auto bFound = std::any_of(rNames.begin(), rNames.end(), + [&aUpperCmp](const ScUnoAddInFuncData::LocalizedName& rName) { + return ScGlobal::pCharClass->uppercase( rName.maName ) == aUpperCmp; }); + if (bFound) { - if ( ScGlobal::pCharClass->uppercase( (*it).maName ) == aUpperCmp ) - { - //TODO: store upper case for comparing? + //TODO: store upper case for comparing? - // use the first function that has this name for any language - rRetCalcName = pFuncData->GetOriginalName(); - return true; - } + // use the first function that has this name for any language + rRetCalcName = pFuncData->GetOriginalName(); + return true; } } } diff --git a/sc/source/core/tool/adiasync.cxx b/sc/source/core/tool/adiasync.cxx index 05502b552625..dc9523005d37 100644 --- a/sc/source/core/tool/adiasync.cxx +++ b/sc/source/core/tool/adiasync.cxx @@ -111,9 +111,8 @@ void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData ) p->bValid = true; p->Broadcast( ScHint(SfxHintId::ScDataChanged, ScAddress()) ); - for ( ScAddInDocs::iterator it = p->pDocs->begin(); it != p->pDocs->end(); ++it ) + for ( ScDocument* pDoc : *p->pDocs ) { - ScDocument* pDoc = *it; pDoc->TrackFormulas(); pDoc->GetDocumentShell()->Broadcast( SfxHint( SfxHintId::ScDataChanged ) ); } diff --git a/sc/source/core/tool/charthelper.cxx b/sc/source/core/tool/charthelper.cxx index b7ca0240bbe9..ff2636bfb230 100644 --- a/sc/source/core/tool/charthelper.cxx +++ b/sc/source/core/tool/charthelper.cxx @@ -135,10 +135,8 @@ void ScChartHelper::AdjustRangesOfChartsOnDestinationPage( const ScDocument* pSr ::std::vector< ScRangeList > aRangesVector; pDestDoc->GetChartRanges( aChartName, aRangesVector, pSrcDoc ); - ::std::vector< ScRangeList >::iterator aIt( aRangesVector.begin() ); - for( ; aIt!=aRangesVector.end(); ++aIt ) + for( ScRangeList& rScRangeList : aRangesVector ) { - ScRangeList& rScRangeList( *aIt ); lcl_AdjustRanges( rScRangeList, nSrcTab, nDestTab, pDestDoc->GetTableCount() ); } pDestDoc->SetChartRanges( aChartName, aRangesVector ); diff --git a/sc/source/core/tool/chartlis.cxx b/sc/source/core/tool/chartlis.cxx index 8ef3edfc1c3d..5717f297c38d 100644 --- a/sc/source/core/tool/chartlis.cxx +++ b/sc/source/core/tool/chartlis.cxx @@ -125,9 +125,8 @@ ScChartListener::~ScChartListener() // Stop listening to all external files. ScExternalRefManager* pRefMgr = mpDoc->GetExternalRefManager(); const std::unordered_set<sal_uInt16>& rFileIds = mpExtRefListener->getAllFileIds(); - std::unordered_set<sal_uInt16>::const_iterator itr = rFileIds.begin(), itrEnd = rFileIds.end(); - for (; itr != itrEnd; ++itr) - pRefMgr->removeLinkListener(*itr, mpExtRefListener.get()); + for (const auto& rFileId : rFileIds) + pRefMgr->removeLinkListener(rFileId, mpExtRefListener.get()); } } @@ -587,11 +586,11 @@ void ScChartListenerCollection::SetRangeDirty( const ScRange& rRange ) StartTimer(); // New hidden range listener implementation - for (auto itr = maHiddenListeners.begin(); itr != maHiddenListeners.end(); ++itr) + for (auto& [pListener, rHiddenRange] : maHiddenListeners) { - if (itr->second.Intersects(rRange)) + if (rHiddenRange.Intersects(rRange)) { - itr->first->notify(); + pListener->notify(); } } } @@ -609,17 +608,13 @@ bool ScChartListenerCollection::operator==( const ScChartListenerCollection& r ) { // Do not use ScStrCollection::operator==() here that uses IsEqual and Compare. // Use ScChartListener::operator==() instead. - if (pDoc != r.pDoc || m_Listeners.size() != r.m_Listeners.size()) + if (pDoc != r.pDoc) return false; - ListenersType::const_iterator it = m_Listeners.begin(), itEnd = m_Listeners.end(); - ListenersType::const_iterator it2 = r.m_Listeners.begin(); - for (; it != itEnd; ++it, ++it2) - { - if (it->first != it2->first || *it->second != *it2->second) - return false; - } - return true; + return std::equal(m_Listeners.begin(), m_Listeners.end(), r.m_Listeners.begin(), r.m_Listeners.end(), + [](const ListenersType::value_type& lhs, const ListenersType::value_type& rhs) { + return (lhs.first == rhs.first) && (*lhs.second == *rhs.second); + }); } void ScChartListenerCollection::StartListeningHiddenRange( const ScRange& rRange, ScChartHiddenRangeListener* pListener ) diff --git a/sc/source/core/tool/chartlock.cxx b/sc/source/core/tool/chartlock.cxx index 12cb2c1b92c4..7496103e5117 100644 --- a/sc/source/core/tool/chartlock.cxx +++ b/sc/source/core/tool/chartlock.cxx @@ -82,13 +82,11 @@ std::vector< WeakReference< frame::XModel > > lcl_getAllLivingCharts( ScDocument ScChartLockGuard::ScChartLockGuard( ScDocument* pDoc ) : maChartModels( lcl_getAllLivingCharts( pDoc ) ) { - std::vector< WeakReference< frame::XModel > >::const_iterator aIter = maChartModels.begin(); - const std::vector< WeakReference< frame::XModel > >::const_iterator aEnd = maChartModels.end(); - for( ; aIter != aEnd; ++aIter ) + for( const auto& rxChartModel : maChartModels ) { try { - Reference< frame::XModel > xModel( *aIter ); + Reference< frame::XModel > xModel( rxChartModel ); if( xModel.is()) xModel->lockControllers(); } @@ -101,13 +99,11 @@ ScChartLockGuard::ScChartLockGuard( ScDocument* pDoc ) : ScChartLockGuard::~ScChartLockGuard() { - std::vector< WeakReference< frame::XModel > >::const_iterator aIter = maChartModels.begin(); - const std::vector< WeakReference< frame::XModel > >::const_iterator aEnd = maChartModels.end(); - for( ; aIter != aEnd; ++aIter ) + for( const auto& rxChartModel : maChartModels ) { try { - Reference< frame::XModel > xModel( *aIter ); + Reference< frame::XModel > xModel( rxChartModel ); if( xModel.is()) xModel->unlockControllers(); } diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx index 3c2df3c1b140..f25d6bb27bbc 100644 --- a/sc/source/core/tool/chgtrack.cxx +++ b/sc/source/core/tool/chgtrack.cxx @@ -482,26 +482,21 @@ void ScChangeAction::GetDescription( { ScChangeActionMap aMap; pCT->GetDependents( pReject, aMap, false, true ); - ScChangeActionMap::iterator itChangeAction; - for( itChangeAction = aMap.begin(); itChangeAction != aMap.end(); ++itChangeAction ) + ScChangeActionMap::iterator itChangeAction = std::find_if(aMap.begin(), aMap.end(), + [&pReject](const ScChangeActionMap::value_type& rEntry) { + return rEntry.second->GetType() == SC_CAT_MOVE || pReject->IsDeleteType(); }); + if (itChangeAction != aMap.end()) { if( itChangeAction->second->GetType() == SC_CAT_MOVE) - { aBuf.append( ScResId(STR_CHANGED_MOVE_REJECTION_WARNING)); - aBuf.append(' '); - rStr = aBuf.makeStringAndClear(); - return; - } - - if (pReject->IsDeleteType()) - { + else aBuf.append( ScResId(STR_CHANGED_DELETE_REJECTION_WARNING)); - aBuf.append(' '); - rStr = aBuf.makeStringAndClear(); - return; - } + + aBuf.append(' '); + rStr = aBuf.makeStringAndClear(); + return; } } } @@ -2127,7 +2122,6 @@ void ScChangeTrack::DtorClear() { ScChangeAction* p; ScChangeAction* pNext; - ScChangeActionMap::iterator itChangeAction; for ( p = GetFirst(); p; p = pNext ) { pNext = p->GetNext(); @@ -2138,9 +2132,9 @@ void ScChangeTrack::DtorClear() pNext = p->GetNext(); delete p; } - for( itChangeAction = aPasteCutMap.begin(); itChangeAction != aPasteCutMap.end(); ++itChangeAction ) + for( auto& rEntry : aPasteCutMap ) { - delete itChangeAction->second; + delete rEntry.second; } pLastCutMove.reset(); ClearMsgQueue(); @@ -4132,13 +4126,12 @@ bool ScChangeTrack::Accept( ScChangeAction* pAct ) if ( pAct->IsDeleteType() || pAct->GetType() == SC_CAT_CONTENT ) { ScChangeActionMap aActionMap; - ScChangeActionMap::iterator itChangeAction; GetDependents( pAct, aActionMap, false, true ); - for( itChangeAction = aActionMap.begin(); itChangeAction != aActionMap.end(); ++itChangeAction ) + for( auto& rEntry : aActionMap ) { - itChangeAction->second->Accept(); + rEntry.second->Accept(); } } pAct->Accept(); diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index e9555399af45..5115f6a187bd 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -242,9 +242,8 @@ std::vector<OUString> &ScCompiler::GetSetupTabNames() const if (pDoc && rTabNames.empty()) { rTabNames = pDoc->GetAllTableNames(); - std::vector<OUString>::iterator it = rTabNames.begin(), itEnd = rTabNames.end(); - for (; it != itEnd; ++it) - ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(meGrammar)); + for (auto& rTabName : rTabNames) + ScCompiler::CheckTabQuotes(rTabName, formula::FormulaGrammar::extractRefConvention(meGrammar)); } return rTabNames; @@ -3559,11 +3558,8 @@ bool ScCompiler::IsColRowName( const OUString& rName ) // Loop through the found positions, similar to the inner part of the loop in the "else" branch. // The order of addresses in the vector is the same as from ScCellIterator. - ScAutoNameAddresses::const_iterator aEnd(rAddresses.end()); - for ( ScAutoNameAddresses::const_iterator aAdrIter(rAddresses.begin()); aAdrIter != aEnd; ++aAdrIter ) + for ( const ScAddress& aAddress : rAddresses ) { - ScAddress aAddress( *aAdrIter ); // cell address with an equal string - if ( bFound ) { // stop if everything else is further away if ( nMax < static_cast<long>(aAddress.Col()) ) diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx index 7b9649125e8d..c2076413e404 100644 --- a/sc/source/core/tool/dbdata.cxx +++ b/sc/source/core/tool/dbdata.cxx @@ -1427,9 +1427,8 @@ void ScDBCollection::DeleteOnTab( SCTAB nTab ) } // Delete them all. - ::std::vector<NamedDBs::DBsType::iterator>::iterator itr = v.begin(), itrEnd = v.end(); - for (; itr != itrEnd; ++itr) - maNamedDBs.erase(*itr); + for (auto& rIter : v) + maNamedDBs.erase(rIter); maAnonDBs.deleteOnTab(nTab); } @@ -1469,23 +1468,22 @@ void ScDBCollection::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos ) ScDBData* ScDBCollection::GetDBNearCursor(SCCOL nCol, SCROW nRow, SCTAB nTab ) { ScDBData* pNearData = nullptr; - NamedDBs::DBsType::iterator itr = maNamedDBs.begin(), itrEnd = maNamedDBs.end(); - for (; itr != itrEnd; ++itr) + for (const auto& rxNamedDB : maNamedDBs) { SCTAB nAreaTab; SCCOL nStartCol, nEndCol; SCROW nStartRow, nEndRow; - (*itr)->GetArea( nAreaTab, nStartCol, nStartRow, nEndCol, nEndRow ); + rxNamedDB->GetArea( nAreaTab, nStartCol, nStartRow, nEndCol, nEndRow ); if ( nTab == nAreaTab && nCol+1 >= nStartCol && nCol <= nEndCol+1 && nRow+1 >= nStartRow && nRow <= nEndRow+1 ) { if ( nCol < nStartCol || nCol > nEndCol || nRow < nStartRow || nRow > nEndRow ) { if (!pNearData) - pNearData = itr->get(); // remember first adjacent area + pNearData = rxNamedDB.get(); // remember first adjacent area } else - return itr->get(); // not "unbenannt"/"unnamed" and cursor within + return rxNamedDB.get(); // not "unbenannt"/"unnamed" and cursor within } } if (pNearData) diff --git a/sc/source/core/tool/detdata.cxx b/sc/source/core/tool/detdata.cxx index 32130e3d35dc..e822d51e3100 100644 --- a/sc/source/core/tool/detdata.cxx +++ b/sc/source/core/tool/detdata.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <algorithm> #include <memory> #include <detdata.hxx> #include <refupdat.hxx> @@ -33,22 +34,19 @@ ScDetOpList::ScDetOpList(const ScDetOpList& rList) : void ScDetOpList::DeleteOnTab( SCTAB nTab ) { - for (ScDetOpDataVector::iterator it = aDetOpDataVector.begin(); it != aDetOpDataVector.end(); /*noop*/ ) - { - // look for operations on the deleted sheet - if ((*it)->GetPos().Tab() == nTab) - it = aDetOpDataVector.erase( it); - else - ++it; - } + aDetOpDataVector.erase(std::remove_if(aDetOpDataVector.begin(), aDetOpDataVector.end(), + [&nTab](const std::unique_ptr<ScDetOpData>& rxDetOpData) { + return rxDetOpData->GetPos().Tab() == nTab; // look for operations on the deleted sheet + }), + aDetOpDataVector.end()); } void ScDetOpList::UpdateReference( const ScDocument* pDoc, UpdateRefMode eUpdateRefMode, const ScRange& rRange, SCCOL nDx, SCROW nDy, SCTAB nDz ) { - for (ScDetOpDataVector::iterator it = aDetOpDataVector.begin(); it != aDetOpDataVector.end(); ++it ) + for (auto& rxDetOpData : aDetOpDataVector ) { - ScAddress aPos = (*it)->GetPos(); + ScAddress aPos = rxDetOpData->GetPos(); SCCOL nCol1 = aPos.Col(); SCROW nRow1 = aPos.Row(); SCTAB nTab1 = aPos.Tab(); @@ -62,7 +60,7 @@ void ScDetOpList::UpdateReference( const ScDocument* pDoc, UpdateRefMode eUpdate rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab(), nDx, nDy, nDz, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 ); if ( eRes != UR_NOTHING ) - (*it)->SetPos( ScAddress( nCol1, nRow1, nTab1 ) ); + rxDetOpData->SetPos( ScAddress( nCol1, nRow1, nTab1 ) ); } } diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx index 5f3af3d55702..17f8b9c8dbfb 100644 --- a/sc/source/core/tool/editutil.cxx +++ b/sc/source/core/tool/editutil.cxx @@ -656,9 +656,8 @@ void ScEditEngineDefaulter::RemoveParaAttribs() // that are not overridden by existing character attributes sal_Int32 nStart = 0; - for ( std::vector<sal_Int32>::const_iterator it(aPortions.begin()); it != aPortions.end(); ++it ) + for ( const sal_Int32 nEnd : aPortions ) { - sal_Int32 nEnd = *it; ESelection aSel( nPar, nStart, nPar, nEnd ); SfxItemSet aOldCharAttrs = GetAttribs( aSel ); SfxItemSet aNewCharAttrs = *pCharItems; diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index e249229dca85..a31897a0de1b 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -6148,10 +6148,12 @@ void ScInterpreter::IterateParametersIfs( double(*ResultFunc)( const sc::ParamIf return; } - std::vector<sal_uInt32>::iterator itRes = vConditions.begin(), itResEnd = vConditions.end(); std::vector<double>::const_iterator itThisRes = aResValues.begin(); - for (; itRes != itResEnd; ++itRes, ++itThisRes) - *itRes += *itThisRes; + for (auto& rCondition : vConditions) + { + rCondition += *itThisRes; + ++itThisRes; + } } else { diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index eeaae0d236a3..b47acaddaf72 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -2441,18 +2441,14 @@ void ScInterpreter::ScIntersect() ScTokenRef xRes = new ScRefListToken; ScRefList* pRefList = xRes->GetRefList(); - ScRefList::const_iterator end1( x1->GetRefList()->end()); - ScRefList::const_iterator end2( x2->GetRefList()->end()); - for (ScRefList::const_iterator it1( x1->GetRefList()->begin()); - it1 != end1; ++it1) - { - const ScAddress& r11 = (*it1).Ref1.toAbs(aPos); - const ScAddress& r12 = (*it1).Ref2.toAbs(aPos); - for (ScRefList::const_iterator it2( x2->GetRefList()->begin()); - it2 != end2; ++it2) + for (const auto& rRef1 : *x1->GetRefList()) + { + const ScAddress& r11 = rRef1.Ref1.toAbs(aPos); + const ScAddress& r12 = rRef1.Ref2.toAbs(aPos); + for (const auto& rRef2 : *x2->GetRefList()) { - const ScAddress& r21 = (*it2).Ref1.toAbs(aPos); - const ScAddress& r22 = (*it2).Ref2.toAbs(aPos); + const ScAddress& r21 = rRef2.Ref1.toAbs(aPos); + const ScAddress& r22 = rRef2.Ref2.toAbs(aPos); SCCOL nCol1 = ::std::max( r11.Col(), r21.Col()); SCROW nRow1 = ::std::max( r11.Row(), r21.Row()); SCTAB nTab1 = ::std::max( r11.Tab(), r21.Tab()); @@ -2616,11 +2612,9 @@ void ScInterpreter::ScUnionFunc() case svRefList: { const ScRefList* p = pt[i]->GetRefList(); - ScRefList::const_iterator it( p->begin()); - ScRefList::const_iterator end( p->end()); - for ( ; it != end; ++it) + for (const auto& rRef : *p) { - pRes->push_back( *it); + pRes->push_back( rRef); } } break; diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 43009c30d180..5c2cd6e97cb7 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -854,11 +854,9 @@ void ScInterpreter::ValidateRef( const ScComplexRefData & rRef ) void ScInterpreter::ValidateRef( const ScRefList & rRefList ) { - ScRefList::const_iterator it( rRefList.begin()); - ScRefList::const_iterator end( rRefList.end()); - for ( ; it != end; ++it) + for (const auto& rRef : rRefList) { - ValidateRef( *it); + ValidateRef( rRef); } } @@ -3570,12 +3568,9 @@ void ScInterpreter::ScTableOp() { pTableOp->aNotifiedFormulaPos = pDok->aLastTableOpParams.aNotifiedFormulaPos; pTableOp->bRefresh = true; - for ( ::std::vector< ScAddress >::const_iterator iBroadcast( - pTableOp->aNotifiedFormulaPos.begin() ); - iBroadcast != pTableOp->aNotifiedFormulaPos.end(); - ++iBroadcast ) + for ( const auto& rPos : pTableOp->aNotifiedFormulaPos ) { // emulate broadcast and indirectly collect cell pointers - ScRefCellValue aCell(*pDok, *iBroadcast); + ScRefCellValue aCell(*pDok, rPos); if (aCell.meType == CELLTYPE_FORMULA) aCell.mpFormula->SetTableOpDirty(); } @@ -3610,12 +3605,9 @@ void ScInterpreter::ScTableOp() } // set dirty again once more to be able to recalculate original - for ( ::std::vector< ScFormulaCell* >::const_iterator iBroadcast( - pTableOp->aNotifiedFormulaCells.begin() ); - iBroadcast != pTableOp->aNotifiedFormulaCells.end(); - ++iBroadcast ) + for ( const auto& pCell : pTableOp->aNotifiedFormulaCells ) { - (*iBroadcast)->SetTableOpDirty(); + pCell->SetTableOpDirty(); } // save these params for next incarnation @@ -3631,12 +3623,9 @@ void ScInterpreter::ScTableOp() // Reset all dirty flags so next incarnation does really collect all cell // pointers during notifications and not just non-dirty ones, which may // happen if a formula cell is used by more than one TableOp block. - for ( ::std::vector< ScFormulaCell* >::const_iterator iBroadcast2( - pTableOp->aNotifiedFormulaCells.begin() ); - iBroadcast2 != pTableOp->aNotifiedFormulaCells.end(); - ++iBroadcast2 ) + for ( const auto& pCell : pTableOp->aNotifiedFormulaCells ) { - (*iBroadcast2)->ResetTableOpDirtyVar(); + pCell->ResetTableOpDirtyVar(); } pTableOp.reset(); diff --git a/sc/source/core/tool/lookupcache.cxx b/sc/source/core/tool/lookupcache.cxx index 5e7890aa2421..9ce48fef696c 100644 --- a/sc/source/core/tool/lookupcache.cxx +++ b/sc/source/core/tool/lookupcache.cxx @@ -98,11 +98,12 @@ ScLookupCache::Result ScLookupCache::lookup( ScAddress & o_rResultAddress, SCROW ScLookupCache::lookup( const QueryCriteria & rCriteria ) const { // try to find the row index for which we have already performed lookup - for (auto it = maQueryMap.begin(); it != maQueryMap.end(); ++it) - { - if (it->second.maCriteria == rCriteria) - return it->first.mnRow; - } + auto it = std::find_if(maQueryMap.begin(), maQueryMap.end(), + [&rCriteria](const std::pair<QueryKey, QueryCriteriaAndResult>& rEntry) { + return rEntry.second.maCriteria == rCriteria; + }); + if (it != maQueryMap.end()) + return it->first.mnRow; // not found return -1; diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx index fab8e1317082..f4507dbe64da 100644 --- a/sc/source/core/tool/queryparam.cxx +++ b/sc/source/core/tool/queryparam.cxx @@ -168,15 +168,11 @@ std::vector<ScQueryEntry*> ScQueryParamBase::FindAllEntriesByField(SCCOLROW nFie { std::vector<ScQueryEntry*> aEntries; - EntriesType::iterator itr = std::find_if( - m_Entries.begin(), m_Entries.end(), FindByField(nField)); + auto fFind = FindByField(nField); - while (itr != m_Entries.end()) - { - aEntries.push_back((*itr).get()); - itr = std::find_if( - itr + 1, m_Entries.end(), FindByField(nField)); - } + for (const auto& rxEntry : m_Entries) + if (fFind(rxEntry)) + aEntries.push_back(rxEntry.get()); return aEntries; } diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx index 575c0eee363d..36fcdb68958e 100644 --- a/sc/source/core/tool/rangelst.cxx +++ b/sc/source/core/tool/rangelst.cxx @@ -1163,13 +1163,11 @@ void ScRangePairList::Remove(size_t nPos) void ScRangePairList::Remove( const ScRangePair & rAdr) { - for ( auto itr = maPairs.begin(); itr != maPairs.end(); ++itr ) + auto itr = std::find_if(maPairs.begin(), maPairs.end(), [&rAdr](const ScRangePair& rPair) { return &rAdr == &rPair; }); + if (itr != maPairs.end()) { - if (&rAdr == &*itr) - { - maPairs.erase( itr ); - return; - } + maPairs.erase( itr ); + return; } assert(false); } @@ -1231,17 +1229,12 @@ void ScRangePairList::UpdateReference( UpdateRefMode eUpdateRefMode, // Delete entries that have the labels (first range) on nTab void ScRangePairList::DeleteOnTab( SCTAB nTab ) { - for (auto it = maPairs.begin(); it != maPairs.end(); ) - { - const ScRangePair & rR = *it; - const ScRange & rRange = rR.GetRange(0); - if ( rRange.aStart.Tab() == nTab && rRange.aEnd.Tab() == nTab ) - { - it = maPairs.erase(it); - } - else - ++it; - } + maPairs.erase(std::remove_if(maPairs.begin(), maPairs.end(), + [&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/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index 419e8b331b6f..76e8656a55c9 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -879,20 +879,10 @@ void ScRangeName::clear() bool ScRangeName::operator== (const ScRangeName& r) const { - if (m_Data.size() != r.m_Data.size()) - { - return false; - } - for (auto iter1 = m_Data.begin(), iter2 = r.m_Data.begin(); - iter1 != m_Data.end(); - ++iter1, ++iter2) - { - if (!(iter1->first == iter2->first && *iter1->second == *iter2->second)) - { - return false; - } - } - return true; + return std::equal(m_Data.begin(), m_Data.end(), r.m_Data.begin(), r.m_Data.end(), + [](const DataType::value_type& lhs, const DataType::value_type& rhs) { + return (lhs.first == rhs.first) && (*lhs.second == *rhs.second); + }); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/tool/reftokenhelper.cxx b/sc/source/core/tool/reftokenhelper.cxx index af6960e1cd48..02980e056bf8 100644 --- a/sc/source/core/tool/reftokenhelper.cxx +++ b/sc/source/core/tool/reftokenhelper.cxx @@ -158,11 +158,10 @@ bool ScRefTokenHelper::getRangeFromToken( void ScRefTokenHelper::getRangeListFromTokens( ScRangeList& rRangeList, const vector<ScTokenRef>& rTokens, const ScAddress& rPos) { - vector<ScTokenRef>::const_iterator itr = rTokens.begin(), itrEnd = rTokens.end(); - for (; itr != itrEnd; ++itr) + for (const auto& rToken : rTokens) { ScRange aRange; - getRangeFromToken(aRange, *itr, rPos); + getRangeFromToken(aRange, rToken, rPos); rRangeList.push_back(aRange); } } @@ -235,10 +234,8 @@ bool ScRefTokenHelper::intersects( ScRange aRange; getRangeFromToken(aRange, pToken, rPos, bExternal); - vector<ScTokenRef>::const_iterator itr = rTokens.begin(), itrEnd = rTokens.end(); - for (; itr != itrEnd; ++itr) + for (const ScTokenRef& p : rTokens) { - const ScTokenRef& p = *itr; if (!isRef(p)) continue; @@ -318,11 +315,8 @@ private: svl::SharedString aTabName = bExternal ? pToken->GetString() : svl::SharedString::getEmptyString(); bool bJoined = false; - vector<ScTokenRef>::iterator itr = rTokens.begin(), itrEnd = rTokens.end(); - for (; itr != itrEnd; ++itr) + for (ScTokenRef& pOldToken : rTokens) { - ScTokenRef& pOldToken = *itr; - if (!ScRefTokenHelper::isRef(pOldToken)) // A non-ref token should not have been added here in the first // place! diff --git a/sc/source/core/tool/sharedformula.cxx b/sc/source/core/tool/sharedformula.cxx index 7a917b1e83d5..7b1bcd319ce5 100644 --- a/sc/source/core/tool/sharedformula.cxx +++ b/sc/source/core/tool/sharedformula.cxx @@ -343,16 +343,15 @@ void SharedFormulaUtil::unshareFormulaCells(CellStoreType& rCells, std::vector<S // Add next cell positions to the list (to ensure that each position becomes a single cell). std::vector<SCROW> aRows2; - std::vector<SCROW>::const_iterator it = rRows.begin(), itEnd = rRows.end(); - for (; it != itEnd; ++it) + for (const auto& rRow : rRows) { - if (*it > MAXROW) + if (rRow > MAXROW) break; - aRows2.push_back(*it); + aRows2.push_back(rRow); - if (*it < MAXROW) - aRows2.push_back(*it+1); + if (rRow < MAXROW) + aRows2.push_back(rRow+1); } // Remove duplicates again (the vector should still be sorted). diff --git a/sc/source/core/tool/simplerangelist.cxx b/sc/source/core/tool/simplerangelist.cxx index fd81db7f2de5..14f7cf94341a 100644 --- a/sc/source/core/tool/simplerangelist.cxx +++ b/sc/source/core/tool/simplerangelist.cxx @@ -132,10 +132,8 @@ void ScSimpleRangeList::insertCol(SCCOL nCol, SCTAB nTab) // This should never happen! return; - list<Range>::iterator itr = pRef->begin(), itrEnd = pRef->end(); - for (; itr != itrEnd; ++itr) + for (Range& r : *pRef) { - Range& r = *itr; if (r.mnCol2 < nCol) // insertion point to the right of the range. continue; @@ -157,14 +155,10 @@ void ScSimpleRangeList::insertCol(SCCOL nCol, SCTAB nTab) void ScSimpleRangeList::getRangeList(list<ScRange>& rList) const { list<ScRange> aList; - for (TabType::const_iterator itrTab = maTabs.begin(), itrTabEnd = maTabs.end(); itrTab != itrTabEnd; ++itrTab) + for (const auto& [nTab, pRanges] : maTabs) { - SCTAB nTab = itrTab->first; - const RangeListRef& pRanges = itrTab->second; - list<Range>::const_iterator itr = pRanges->begin(), itrEnd = pRanges->end(); - for (; itr != itrEnd; ++itr) + for (const Range& r : *pRanges) { - const Range& r = *itr; aList.emplace_back(r.mnCol1, r.mnRow1, nTab, r.mnCol2, r.mnRow2, nTab); } } diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index c1fb5e2e9de6..c4cf19cb71ec 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -596,11 +596,9 @@ FormulaTokenRef extendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2 const ScRefList* p = pt[i]->GetRefList(); if (p->empty()) return nullptr; - ScRefList::const_iterator it( p->begin()); - ScRefList::const_iterator end( p->end()); - for ( ; it != end; ++it) + for (const auto& rRefData : *p) { - rRef.Extend( *it, rPos); + rRef.Extend( rRefData, rPos); } } break; diff --git a/sc/source/core/tool/tokenstringcontext.cxx b/sc/source/core/tool/tokenstringcontext.cxx index 657915986b5b..b5ec7d5356e3 100644 --- a/sc/source/core/tool/tokenstringcontext.cxx +++ b/sc/source/core/tool/tokenstringcontext.cxx @@ -52,9 +52,8 @@ TokenStringContext::TokenStringContext( const ScDocument* pDoc, formula::Formula // Fetch all sheet names. maTabNames = pDoc->GetAllTableNames(); { - std::vector<OUString>::iterator it = maTabNames.begin(), itEnd = maTabNames.end(); - for (; it != itEnd; ++it) - ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(eGram)); + for (auto& rTabName : maTabNames) + ScCompiler::CheckTabQuotes(rTabName, formula::FormulaGrammar::extractRefConvention(eGram)); } // Fetch all named range names. @@ -66,14 +65,11 @@ TokenStringContext::TokenStringContext( const ScDocument* pDoc, formula::Formula { ScRangeName::TabNameCopyMap aTabRangeNames; pDoc->GetAllTabRangeNames(aTabRangeNames); - ScRangeName::TabNameCopyMap::const_iterator it = aTabRangeNames.begin(), itEnd = aTabRangeNames.end(); - for (; it != itEnd; ++it) + for (const auto& [nTab, pSheetNames] : aTabRangeNames) { - const ScRangeName* pSheetNames = it->second; if (!pSheetNames) continue; - SCTAB nTab = it->first; IndexNameMapType aNames; insertAllNames(aNames, *pSheetNames); maSheetRangeNames.emplace(nTab, aNames); @@ -85,10 +81,9 @@ TokenStringContext::TokenStringContext( const ScDocument* pDoc, formula::Formula if (pDBs) { const ScDBCollection::NamedDBs& rNamedDBs = pDBs->getNamedDBs(); - ScDBCollection::NamedDBs::const_iterator it = rNamedDBs.begin(), itEnd = rNamedDBs.end(); - for (; it != itEnd; ++it) + for (const auto& rxNamedDB : rNamedDBs) { - const ScDBData& rData = **it; + const ScDBData& rData = *rxNamedDB; maNamedDBs.emplace(rData.GetIndex(), rData.GetName()); } } @@ -126,9 +121,8 @@ void CompileFormulaContext::updateTabNames() // Fetch all sheet names. maTabNames = mpDoc->GetAllTableNames(); { - std::vector<OUString>::iterator it = maTabNames.begin(), itEnd = maTabNames.end(); - for (; it != itEnd; ++it) - ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(meGram)); + for (auto& rTabName : maTabNames) + ScCompiler::CheckTabQuotes(rTabName, formula::FormulaGrammar::extractRefConvention(meGram)); } } diff --git a/sc/source/core/tool/userlist.cxx b/sc/source/core/tool/userlist.cxx index 30ac7cc4b71f..35e931f2d0b4 100644 --- a/sc/source/core/tool/userlist.cxx +++ b/sc/source/core/tool/userlist.cxx @@ -277,18 +277,17 @@ ScUserList::ScUserList(const ScUserList& rOther) const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const { const ScUserListData* pFirstCaseInsensitive = nullptr; - DataType::const_iterator itr = maData.begin(), itrEnd = maData.end(); sal_uInt16 nIndex; bool bMatchCase = false; - for (; itr != itrEnd; ++itr) + for (const auto& rxItem : maData) { - if ((*itr)->GetSubIndex(rSubStr, nIndex, bMatchCase)) + if (rxItem->GetSubIndex(rSubStr, nIndex, bMatchCase)) { if (bMatchCase) - return itr->get(); + return rxItem.get(); if (!pFirstCaseInsensitive) - pFirstCaseInsensitive = itr->get(); + pFirstCaseInsensitive = rxItem.get(); } } @@ -315,18 +314,10 @@ ScUserList& ScUserList::operator=( const ScUserList& rOther ) bool ScUserList::operator==( const ScUserList& r ) const { - if (size() != r.size()) - return false; - - DataType::const_iterator itr1 = maData.begin(), itr2 = r.maData.begin(), itrEnd = maData.end(); - for (; itr1 != itrEnd; ++itr1, ++itr2) - { - const ScUserListData& v1 = **itr1; - const ScUserListData& v2 = **itr2; - if (v1.GetString() != v2.GetString() || v1.GetSubCount() != v2.GetSubCount()) - return false; - } - return true; + return std::equal(maData.begin(), maData.end(), r.maData.begin(), r.maData.end(), + [](const std::unique_ptr<ScUserListData>& lhs, const std::unique_ptr<ScUserListData>& rhs) { + return (lhs->GetString() == rhs->GetString()) && (lhs->GetSubCount() == rhs->GetSubCount()); + }); } bool ScUserList::operator!=( const ScUserList& r ) const |