[Libreoffice-commits] core.git: sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Feb 13 09:26:33 UTC 2019


 sc/source/core/data/documentimport.cxx  |   14 --
 sc/source/core/data/dpcache.cxx         |   20 +--
 sc/source/core/data/dpdimsave.cxx       |  124 +++++++------------
 sc/source/core/data/dpfilteredcache.cxx |   11 -
 sc/source/core/data/dpgroup.cxx         |  140 +++++++++------------
 sc/source/core/data/dpobject.cxx        |  117 ++++++------------
 sc/source/core/data/dpresfilter.cxx     |   16 --
 sc/source/core/data/dpsave.cxx          |  125 +++++++------------
 sc/source/core/data/dptabres.cxx        |   54 ++------
 sc/source/core/data/dptabsrc.cxx        |   47 ++-----
 sc/source/core/data/drwlayer.cxx        |   15 --
 sc/source/core/data/fillinfo.cxx        |    8 -
 sc/source/core/data/formulacell.cxx     |    5 
 sc/source/core/data/markdata.cxx        |   27 +---
 sc/source/core/data/olinetab.cxx        |   78 +++++-------
 sc/source/core/data/pivot2.cxx          |    5 
 sc/source/core/data/stlpool.cxx         |    5 
 sc/source/core/data/table1.cxx          |   12 -
 sc/source/core/data/table2.cxx          |   36 ++---
 sc/source/core/data/table3.cxx          |  205 ++++++++++++--------------------
 sc/source/core/data/table4.cxx          |   30 +---
 sc/source/core/data/table5.cxx          |   16 +-
 sc/source/core/data/tabprotection.cxx   |   45 ++-----
 sc/source/core/data/validat.cxx         |    8 -
 24 files changed, 475 insertions(+), 688 deletions(-)

New commits:
commit 49bc42bfd2b164d61603f138eeb2292f5d89605b
Author:     Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sat Feb 9 17:14:17 2019 +0300
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Feb 13 10:26:00 2019 +0100

    Simplify containers iterations in sc/source/core/data
    
    From documentimport.cxx to validat.cxx
    Use range-based loop or replace with STL functions
    
    Change-Id: I59fb3ed20598e497b5653245f070298181da1331
    Reviewed-on: https://gerrit.libreoffice.org/67587
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index 4da6d7473894..ebe1b8a6dfc8 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -698,13 +698,12 @@ void ScDocumentImport::finalize()
 {
     // Populate the text width and script type arrays in all columns. Also
     // activate all formula cells.
-    ScDocument::TableContainer::iterator itTab = mpImpl->mrDoc.maTabs.begin(), itTabEnd = mpImpl->mrDoc.maTabs.end();
-    for (; itTab != itTabEnd; ++itTab)
+    for (auto& rxTab : mpImpl->mrDoc.maTabs)
     {
-        if (!*itTab)
+        if (!rxTab)
             continue;
 
-        ScTable& rTab = **itTab;
+        ScTable& rTab = *rxTab;
         SCCOL nNumCols = rTab.aCol.size();
         for (SCCOL nColIdx = 0; nColIdx < nNumCols; ++nColIdx)
             initColumn(rTab.aCol[nColIdx]);
@@ -755,13 +754,12 @@ void ScDocumentImport::broadcastRecalcAfterImport()
     sc::AutoCalcSwitch aACSwitch( mpImpl->mrDoc, false);
     ScBulkBroadcast aBulkBroadcast( mpImpl->mrDoc.GetBASM(), SfxHintId::ScDataChanged);
 
-    ScDocument::TableContainer::iterator itTab = mpImpl->mrDoc.maTabs.begin(), itTabEnd = mpImpl->mrDoc.maTabs.end();
-    for (; itTab != itTabEnd; ++itTab)
+    for (auto& rxTab : mpImpl->mrDoc.maTabs)
     {
-        if (!*itTab)
+        if (!rxTab)
             continue;
 
-        ScTable& rTab = **itTab;
+        ScTable& rTab = *rxTab;
         SCCOL nNumCols = rTab.aCol.size();
         for (SCCOL nColIdx = 0; nColIdx < nNumCols; ++nColIdx)
             broadcastRecalcAfterImportColumn(rTab.aCol[nColIdx]);
diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx
index 1be6e523966c..60011acd6317 100644
--- a/sc/source/core/data/dpcache.cxx
+++ b/sc/source/core/data/dpcache.cxx
@@ -1452,9 +1452,8 @@ void dumpItems(const ScDPCache& rCache, long nDim, const ScDPCache::ScDPItemData
 
 void dumpSourceData(const ScDPCache& rCache, long nDim, const ScDPCache::ScDPItemDataVec& rItems, const ScDPCache::IndexArrayType& rArray)
 {
-    ScDPCache::IndexArrayType::const_iterator it = rArray.begin(), itEnd = rArray.end();
-    for (; it != itEnd; ++it)
-        cout << "      '" << rCache.GetFormattedString(nDim, rItems[*it], false) << "'" << endl;
+    for (const auto& rIndex : rArray)
+        cout << "      '" << rCache.GetFormattedString(nDim, rItems[rIndex], false) << "'" << endl;
 }
 
 const char* getGroupTypeName(sal_Int32 nType)
@@ -1489,10 +1488,10 @@ void ScDPCache::Dump() const
 
     cout << "--- pivot cache dump" << endl;
     {
-        FieldsType::const_iterator it = maFields.begin(), itEnd = maFields.end();
-        for (size_t i = 0; it != itEnd; ++it, ++i)
+        size_t i = 0;
+        for (const auto& rxField : maFields)
         {
-            const Field& fld = *(*it);
+            const Field& fld = *rxField;
             cout << "* source dimension: " << GetDimensionName(i) << " (ID = " << i << ")" << endl;
             cout << "    item count: " << fld.maItems.size() << endl;
             if (bDumpItems)
@@ -1510,19 +1509,22 @@ void ScDPCache::Dump() const
                 cout << "    source data (re-constructed):" << endl;
                 dumpSourceData(*this, i, fld.maItems, fld.maData);
             }
+
+            ++i;
         }
     }
 
     {
-        GroupFieldsType::const_iterator it = maGroupFields.begin(), itEnd = maGroupFields.end();
-        for (size_t i = maFields.size(); it != itEnd; ++it, ++i)
+        size_t i = maFields.size();
+        for (const auto& rxGroupField : maGroupFields)
         {
-            const GroupItems& gi = *(*it);
+            const GroupItems& gi = *rxGroupField;
             cout << "* group dimension: (unnamed) (ID = " << i << ")" << endl;
             cout << "    item count: " << gi.maItems.size() << endl;
             cout << "    group type: " << getGroupTypeName(gi.mnGroupType) << endl;
             if (bDumpItems)
                 dumpItems(*this, i, gi.maItems, 0);
+            ++i;
         }
     }
 
diff --git a/sc/source/core/data/dpdimsave.cxx b/sc/source/core/data/dpdimsave.cxx
index f2f87aa668e1..ef7be61cc821 100644
--- a/sc/source/core/data/dpdimsave.cxx
+++ b/sc/source/core/data/dpdimsave.cxx
@@ -50,9 +50,8 @@ void ScDPSaveGroupItem::AddElementsFromGroup( const ScDPSaveGroupItem& rGroup )
 {
     // add all elements of the other group (used for nested grouping)
 
-    for ( std::vector<OUString>::const_iterator aIter(rGroup.aElements.begin());
-                                aIter != rGroup.aElements.end(); ++aIter )
-        aElements.push_back( *aIter );
+    for ( const auto& rElement : rGroup.aElements )
+        aElements.push_back( rElement );
 }
 
 bool ScDPSaveGroupItem::RemoveElement( const OUString& rName )
@@ -91,23 +90,22 @@ void ScDPSaveGroupItem::RemoveElementsFromGroups( ScDPSaveGroupDimension& rDimen
     // remove this group's elements from their groups in rDimension
     // (rDimension must be a different dimension from the one which contains this)
 
-    for ( std::vector<OUString>::const_iterator aIter(aElements.begin()); aIter != aElements.end(); ++aIter )
-        rDimension.RemoveFromGroups( *aIter );
+    for ( const auto& rElement : aElements )
+        rDimension.RemoveFromGroups( rElement );
 }
 
 void ScDPSaveGroupItem::ConvertElementsToItems(SvNumberFormatter* pFormatter) const
 {
     maItems.reserve(aElements.size());
-    std::vector<OUString>::const_iterator it = aElements.begin(), itEnd = aElements.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rElement : aElements)
     {
         sal_uInt32 nFormat = 0;
         double fValue;
         ScDPItemData aData;
-        if (pFormatter->IsNumberFormat(*it, nFormat, fValue))
+        if (pFormatter->IsNumberFormat(rElement, nFormat, fValue))
             aData.SetValue(fValue);
         else
-            aData.SetString(*it);
+            aData.SetString(rElement);
 
         maItems.push_back(aData);
     }
@@ -121,9 +119,8 @@ bool ScDPSaveGroupItem::HasInGroup(const ScDPItemData& rItem) const
 void ScDPSaveGroupItem::AddToData(ScDPGroupDimension& rDataDim) const
 {
     ScDPGroupItem aGroup(aGroupName);
-    std::vector<ScDPItemData>::const_iterator it = maItems.begin(), itEnd = maItems.end();
-    for (; it != itEnd; ++it)
-        aGroup.AddElement(*it);
+    for (const auto& rItem : maItems)
+        aGroup.AddElement(rItem);
 
     rDataDim.AddItem(aGroup);
 }
@@ -166,13 +163,12 @@ OUString ScDPSaveGroupDimension::CreateGroupName(const OUString& rPrefix)
     while ( nAdd <= nMaxAdd )
     {
         OUString aGroupName = rPrefix + OUString::number( nAdd );
-        bool bExists = false;
 
         // look for existing groups
-        for ( ScDPSaveGroupItemVec::const_iterator aIter(aGroups.begin());
-                                    aIter != aGroups.end() && !bExists; ++aIter )
-            if (aIter->GetGroupName() == aGroupName)         //TODO: ignore case
-                bExists = true;
+        bool bExists = std::any_of(aGroups.begin(), aGroups.end(),
+            [&aGroupName](const ScDPSaveGroupItem& rGroup) {
+                return rGroup.GetGroupName() == aGroupName; //TODO: ignore case
+            });
 
         if ( !bExists )
             return aGroupName;          // found a new name
@@ -191,9 +187,12 @@ const ScDPSaveGroupItem* ScDPSaveGroupDimension::GetNamedGroup( const OUString&
 
 ScDPSaveGroupItem* ScDPSaveGroupDimension::GetNamedGroupAcc( const OUString& rGroupName )
 {
-    for (ScDPSaveGroupItemVec::iterator aIter = aGroups.begin(); aIter != aGroups.end(); ++aIter)
-        if (aIter->GetGroupName() == rGroupName)         //TODO: ignore case
-            return &*aIter;
+    auto aIter = std::find_if(aGroups.begin(), aGroups.end(),
+        [&rGroupName](const ScDPSaveGroupItem& rGroup) {
+            return rGroup.GetGroupName() == rGroupName; //TODO: ignore case
+        });
+    if (aIter != aGroups.end())
+        return &*aIter;
 
     return nullptr;        // none found
 }
@@ -226,12 +225,12 @@ void ScDPSaveGroupDimension::RemoveFromGroups( const OUString& rItemName )
 
 void ScDPSaveGroupDimension::RemoveGroup(const OUString& rGroupName)
 {
-    for (ScDPSaveGroupItemVec::iterator aIter = aGroups.begin(); aIter != aGroups.end(); ++aIter)
-        if (aIter->GetGroupName() == rGroupName)          //TODO: ignore case
-        {
-            aGroups.erase( aIter );
-            return;                     // don't have to look further
-        }
+    auto aIter = std::find_if(aGroups.begin(), aGroups.end(),
+        [&rGroupName](const ScDPSaveGroupItem& rGroup) {
+            return rGroup.GetGroupName() == rGroupName; //TODO: ignore case
+        });
+    if (aIter != aGroups.end())
+        aGroups.erase( aIter );
 }
 
 bool ScDPSaveGroupDimension::IsEmpty() const
@@ -243,13 +242,8 @@ bool ScDPSaveGroupDimension::HasOnlyHidden(const ScDPUniqueStringSet& rVisible)
 {
     // check if there are only groups that don't appear in the list of visible names
 
-    bool bAllHidden = true;
-    for (ScDPSaveGroupItemVec::const_iterator aIter = aGroups.begin(); aIter != aGroups.end() && bAllHidden; ++aIter)
-    {
-        if (rVisible.count(aIter->GetGroupName()) > 0)
-            bAllHidden = false;
-    }
-    return bAllHidden;
+    return std::none_of(aGroups.begin(), aGroups.end(),
+        [&rVisible](const ScDPSaveGroupItem& rGroup) { return rVisible.count(rGroup.GetGroupName()) > 0; });
 }
 
 void ScDPSaveGroupDimension::Rename( const OUString& rNewName )
@@ -259,13 +253,8 @@ void ScDPSaveGroupDimension::Rename( const OUString& rNewName )
 
 bool ScDPSaveGroupDimension::IsInGroup(const ScDPItemData& rItem) const
 {
-    ScDPSaveGroupItemVec::const_iterator it = aGroups.begin(), itEnd = aGroups.end();
-    for (; it != itEnd; ++it)
-    {
-        if (it->HasInGroup(rItem))
-            return true;
-    }
-    return false;
+    return std::any_of(aGroups.begin(), aGroups.end(),
+        [&rItem](const ScDPSaveGroupItem& rGroup) { return rGroup.HasInGroup(rItem); });
 }
 
 namespace {
@@ -286,10 +275,8 @@ void fillDateGroupDimension(
     bool bFirst = true;
 
     const ScDPCache::ScDPItemDataVec& rItems = rCache.GetDimMemberValues(nSourceDim);
-    ScDPCache::ScDPItemDataVec::const_iterator it = rItems.begin(), itEnd = rItems.end();
-    for (; it != itEnd; ++it)
+    for (const ScDPItemData& rItem : rItems)
     {
-        const ScDPItemData& rItem = *it;
         if (rItem.GetType() != ScDPItemData::Value)
             continue;
 
@@ -366,8 +353,8 @@ void ScDPSaveGroupDimension::AddToData( ScDPGroupTableData& rData ) const
         {
             // normal (manual) grouping
 
-            for (ScDPSaveGroupItemVec::const_iterator aIter(aGroups.begin()); aIter != aGroups.end(); ++aIter)
-                aIter->AddToData(aDim);
+            for (const auto& rGroup : aGroups)
+                rGroup.AddToData(aDim);
         }
 
         rData.AddGroupDimension( aDim );
@@ -390,26 +377,18 @@ void ScDPSaveGroupDimension::AddToCache(ScDPCache& rCache) const
     }
 
     rCache.ResetGroupItems(nDim, aDateInfo, 0);
+    for (const ScDPSaveGroupItem& rGI : aGroups)
     {
-        ScDPSaveGroupItemVec::const_iterator it = aGroups.begin(), itEnd = aGroups.end();
-        for (; it != itEnd; ++it)
-        {
-            const ScDPSaveGroupItem& rGI = *it;
-            rGI.ConvertElementsToItems(pFormatter);
-            rCache.SetGroupItem(nDim, ScDPItemData(rGI.GetGroupName()));
-        }
+        rGI.ConvertElementsToItems(pFormatter);
+        rCache.SetGroupItem(nDim, ScDPItemData(rGI.GetGroupName()));
     }
 
     const ScDPCache::ScDPItemDataVec& rItems = rCache.GetDimMemberValues(nSourceDim);
+    for (const ScDPItemData& rItem : rItems)
     {
-        ScDPCache::ScDPItemDataVec::const_iterator it = rItems.begin(), itEnd = rItems.end();
-        for (; it != itEnd; ++it)
-        {
-            const ScDPItemData& rItem = *it;
-            if (!IsInGroup(rItem))
-                // Not in any group.  Add as its own group.
-                rCache.SetGroupItem(nDim, rItem);
-        }
+        if (!IsInGroup(rItem))
+            // Not in any group.  Add as its own group.
+            rCache.SetGroupItem(nDim, rItem);
     }
 }
 
@@ -470,10 +449,8 @@ void ScDPSaveNumGroupDimension::AddToCache(ScDPCache& rCache) const
         bool bFirst = true;
 
         const ScDPCache::ScDPItemDataVec& rItems = rCache.GetDimMemberValues(nDim);
-        ScDPCache::ScDPItemDataVec::const_iterator it = rItems.begin(), itEnd = rItems.end();
-        for (; it != itEnd; ++it)
+        for (const ScDPItemData& rItem : rItems)
         {
-            const ScDPItemData& rItem = *it;
             if (rItem.GetType() != ScDPItemData::Value)
                 continue;
 
@@ -637,11 +614,11 @@ void ScDPDimensionSaveData::WriteToData( ScDPGroupTableData& rData ) const
     //  rData is assumed to be empty
     //  AddToData also handles date grouping
 
-    for( ScDPSaveGroupDimVec::const_iterator aIt = maGroupDims.begin(), aEnd = maGroupDims.end(); aIt != aEnd; ++aIt )
-        aIt->AddToData( rData );
+    for( const auto& rGroupDim : maGroupDims )
+        rGroupDim.AddToData( rData );
 
-    for( ScDPSaveNumGroupDimMap::const_iterator aIt = maNumGroupDims.begin(), aEnd = maNumGroupDims.end(); aIt != aEnd; ++aIt )
-        aIt->second.AddToData( rData );
+    for( const auto& rEntry : maNumGroupDims )
+        rEntry.second.AddToData( rData );
 }
 
 namespace {
@@ -662,9 +639,8 @@ public:
 void ScDPDimensionSaveData::WriteToCache(ScDPCache& rCache) const
 {
     std::for_each(maGroupDims.begin(), maGroupDims.end(), AddGroupDimToCache(rCache));
-    ScDPSaveNumGroupDimMap::const_iterator it = maNumGroupDims.begin(), itEnd = maNumGroupDims.end();
-    for (; it != itEnd; ++it)
-        it->second.AddToCache(rCache);
+    for (const auto& rEntry : maNumGroupDims)
+        rEntry.second.AddToCache(rCache);
 }
 
 const ScDPSaveGroupDimension* ScDPDimensionSaveData::GetGroupDimForBase( const OUString& rBaseDimName ) const
@@ -763,12 +739,12 @@ OUString ScDPDimensionSaveData::CreateGroupDimName(
         OUString aDimName( rSourceName );
         if ( !bUseSource )
             aDimName += OUString::number(nAdd);
-        bool bExists = false;
 
         // look for existing group dimensions
-        for( ScDPSaveGroupDimVec::const_iterator aIt = maGroupDims.begin(), aEnd = maGroupDims.end(); (aIt != aEnd) && !bExists; ++aIt )
-            if( aIt->GetGroupDimName() == aDimName )         //TODO: ignore case
-                bExists = true;
+        bool bExists = std::any_of(maGroupDims.begin(), maGroupDims.end(),
+            [&aDimName](const ScDPSaveGroupDimension& rDim) {
+                return rDim.GetGroupDimName() == aDimName; //TODO: ignore case
+            });
 
         // look for base dimensions that happen to have that name
         if ( !bExists && rObject.IsDimNameInUse( aDimName ) )
diff --git a/sc/source/core/data/dpfilteredcache.cxx b/sc/source/core/data/dpfilteredcache.cxx
index f46c6cd96065..0763aee3152b 100644
--- a/sc/source/core/data/dpfilteredcache.cxx
+++ b/sc/source/core/data/dpfilteredcache.cxx
@@ -372,18 +372,17 @@ bool ScDPFilteredCache::isRowQualified(sal_Int32 nRow, const vector<Criterion>&
                                     const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims) const
 {
     sal_Int32 nColSize = getColSize();
-    vector<Criterion>::const_iterator itrEnd = rCriteria.end();
-    for (vector<Criterion>::const_iterator itr = rCriteria.begin(); itr != itrEnd; ++itr)
+    for (const auto& rCriterion : rCriteria)
     {
-        if (itr->mnFieldIndex >= nColSize)
+        if (rCriterion.mnFieldIndex >= nColSize)
             // specified field is outside the source data columns.  Don't
             // use this criterion.
             continue;
 
         // Check if the 'repeat if empty' flag is set for this field.
-        bool bRepeatIfEmpty = rRepeatIfEmptyDims.count(itr->mnFieldIndex) > 0;
-        const ScDPItemData* pCellData = getCell(static_cast<SCCOL>(itr->mnFieldIndex), nRow, bRepeatIfEmpty);
-        if (!itr->mpFilter->match(*pCellData))
+        bool bRepeatIfEmpty = rRepeatIfEmptyDims.count(rCriterion.mnFieldIndex) > 0;
+        const ScDPItemData* pCellData = getCell(static_cast<SCCOL>(rCriterion.mnFieldIndex), nRow, bRepeatIfEmpty);
+        if (!rCriterion.mpFilter->match(*pCellData))
             return false;
     }
     return true;
diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx
index 34fc1a0e0259..0327dcb5c44f 100644
--- a/sc/source/core/data/dpgroup.cxx
+++ b/sc/source/core/data/dpgroup.cxx
@@ -63,10 +63,9 @@ bool ScDPGroupNumFilter::match(const ScDPItemData& rCellData) const
     if (rCellData.GetType() != ScDPItemData::Value)
         return false;
 
-    std::vector<ScDPItemData>::const_iterator it = maValues.begin(), itEnd = maValues.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rValue : maValues)
     {
-        double fVal = it->GetValue();
+        double fVal = rValue.GetValue();
         if (rtl::math::isInf(fVal))
         {
             if (rtl::math::isSignBitSet(fVal))
@@ -132,10 +131,8 @@ bool ScDPGroupDateFilter::match( const ScDPItemData & rCellData ) const
     if ( !rCellData.IsValue() )
         return false;
 
-    std::vector<ScDPItemData>::const_iterator it = maValues.begin(), itEnd = maValues.end();
-    for (; it != itEnd; ++it)
+    for (const ScDPItemData& rValue : maValues)
     {
-        const ScDPItemData& rValue = *it;
         if (rValue.GetType() != ScDPItemData::GroupValue)
             continue;
 
@@ -312,27 +309,20 @@ void ScDPGroupItem::AddElement( const ScDPItemData& rName )
 
 bool ScDPGroupItem::HasElement( const ScDPItemData& rData ) const
 {
-    for ( ScDPItemDataVec::const_iterator aIter(aElements.begin()); aIter != aElements.end(); ++aIter )
-        if ( aIter->IsCaseInsEqual( rData ) )
-            return true;
-
-    return false;
+    return std::any_of(aElements.begin(), aElements.end(),
+        [&rData](const ScDPItemData& rElement) { return rElement.IsCaseInsEqual(rData); });
 }
 
 bool ScDPGroupItem::HasCommonElement( const ScDPGroupItem& rOther ) const
 {
-    for ( ScDPItemDataVec::const_iterator aIter(aElements.begin()); aIter != aElements.end(); ++aIter )
-        if ( rOther.HasElement( *aIter ) )
-            return true;
-
-    return false;
+    return std::any_of(aElements.begin(), aElements.end(),
+        [&rOther](const ScDPItemData& rElement) { return rOther.HasElement(rElement); });
 }
 
 void ScDPGroupItem::FillGroupFilter( ScDPFilteredCache::GroupFilter& rFilter ) const
 {
-    ScDPItemDataVec::const_iterator itrEnd = aElements.end();
-    for (ScDPItemDataVec::const_iterator itr = aElements.begin(); itr != itrEnd; ++itr)
-        rFilter.addMatchItem(*itr);
+    for (const auto& rElement : aElements)
+        rFilter.addMatchItem(rElement);
 }
 
 ScDPGroupDimension::ScDPGroupDimension( long nSource, const OUString& rNewName ) :
@@ -389,18 +379,20 @@ const std::vector<SCROW>& ScDPGroupDimension::GetColumnEntries(
 
 const ScDPGroupItem* ScDPGroupDimension::GetGroupForData( const ScDPItemData& rData ) const
 {
-    for (ScDPGroupItemVec::const_iterator aIter = aItems.begin(); aIter != aItems.end(); ++aIter)
-        if (aIter->HasElement(rData))
-            return &*aIter;
+    auto aIter = std::find_if(aItems.begin(), aItems.end(),
+        [&rData](const ScDPGroupItem& rItem) { return rItem.HasElement(rData); });
+    if (aIter != aItems.end())
+        return &*aIter;
 
     return nullptr;
 }
 
 const ScDPGroupItem* ScDPGroupDimension::GetGroupForName( const ScDPItemData& rName ) const
 {
-    for ( ScDPGroupItemVec::const_iterator aIter(aItems.begin()); aIter != aItems.end(); ++aIter )
-        if ( aIter->GetName().IsCaseInsEqual( rName ) )
-            return &*aIter;
+    auto aIter = std::find_if(aItems.begin(), aItems.end(),
+        [&rName](const ScDPGroupItem& rItem) { return rItem.GetName().IsCaseInsEqual(rName); });
+    if (aIter != aItems.end())
+        return &*aIter;
 
     return nullptr;
 }
@@ -600,8 +592,8 @@ sal_uInt32 ScDPGroupTableData::GetNumberFormat(long nDim)
 
 void ScDPGroupTableData::DisposeData()
 {
-    for ( ScDPGroupDimensionVec::iterator aIter(aGroups.begin()); aIter != aGroups.end(); ++aIter )
-        aIter->DisposeData();
+    for ( auto& rGroup : aGroups )
+        rGroup.DisposeData();
 
     for ( long i=0; i<nSourceCount; i++ )
         pNumGroups[i].DisposeData();
@@ -645,12 +637,10 @@ void ScDPGroupTableData::ModifyFilterCriteria(vector<ScDPFilteredCache::Criterio
     // Build dimension ID to object map for group dimensions.
     typedef std::unordered_map<long, const ScDPGroupDimension*> GroupFieldMapType;
     GroupFieldMapType aGroupFieldIds;
+
+    for (const auto& rGroup : aGroups)
     {
-        ScDPGroupDimensionVec::const_iterator itr = aGroups.begin(), itrEnd = aGroups.end();
-        for (; itr != itrEnd; ++itr)
-        {
-            aGroupFieldIds.emplace(itr->GetGroupDim(), &(*itr));
-        }
+        aGroupFieldIds.emplace(rGroup.GetGroupDim(), &rGroup);
     }
 
     vector<ScDPFilteredCache::Criterion> aNewCriteria;
@@ -659,26 +649,25 @@ void ScDPGroupTableData::ModifyFilterCriteria(vector<ScDPFilteredCache::Criterio
     // Go through all the filtered field names and process them appropriately.
 
     const ScDPCache& rCache = GetCacheTable().getCache();
-    vector<ScDPFilteredCache::Criterion>::const_iterator itrEnd = rCriteria.end();
     GroupFieldMapType::const_iterator itrGrpEnd = aGroupFieldIds.end();
-    for (vector<ScDPFilteredCache::Criterion>::const_iterator itr = rCriteria.begin(); itr != itrEnd; ++itr)
+    for (const auto& rCriterion : rCriteria)
     {
-        std::vector<ScDPItemData> aMatchValues = itr->mpFilter->getMatchValues();
+        std::vector<ScDPItemData> aMatchValues = rCriterion.mpFilter->getMatchValues();
 
-        GroupFieldMapType::const_iterator itrGrp = aGroupFieldIds.find(itr->mnFieldIndex);
+        GroupFieldMapType::const_iterator itrGrp = aGroupFieldIds.find(rCriterion.mnFieldIndex);
         if (itrGrp == itrGrpEnd)
         {
-            if (IsNumGroupDimension(itr->mnFieldIndex))
+            if (IsNumGroupDimension(rCriterion.mnFieldIndex))
             {
                 // internal number group field
-                const ScDPNumGroupInfo* pNumInfo = rCache.GetNumGroupInfo(itr->mnFieldIndex);
+                const ScDPNumGroupInfo* pNumInfo = rCache.GetNumGroupInfo(rCriterion.mnFieldIndex);
                 if (!pNumInfo)
                     // Number group dimension without num info?  Something is wrong...
                     continue;
 
                 ScDPFilteredCache::Criterion aCri;
-                aCri.mnFieldIndex = itr->mnFieldIndex;
-                const ScDPNumGroupDimension& rNumGrpDim = pNumGroups[itr->mnFieldIndex];
+                aCri.mnFieldIndex = rCriterion.mnFieldIndex;
+                const ScDPNumGroupDimension& rNumGrpDim = pNumGroups[rCriterion.mnFieldIndex];
 
                 if (rNumGrpDim.IsDateDimension())
                 {
@@ -699,7 +688,7 @@ void ScDPGroupTableData::ModifyFilterCriteria(vector<ScDPFilteredCache::Criterio
             else
             {
                 // This is a regular source field.
-                aNewCriteria.push_back(*itr);
+                aNewCriteria.push_back(rCriterion);
             }
         }
         else
@@ -813,10 +802,9 @@ void ScDPGroupTableData::FillGroupValues(vector<SCROW>& rItems, const vector<lon
     long nGroupedColumns = aGroups.size();
 
     const ScDPCache& rCache = GetCacheTable().getCache();
-    vector<long>::const_iterator it = rDims.begin(), itEnd = rDims.end();
-    for (size_t i = 0; it != itEnd; ++it, ++i)
+    size_t i = 0;
+    for (long nColumn : rDims)
     {
-        long nColumn = *it;
         bool bDateDim = false;
 
         long nSourceDim = nColumn;
@@ -874,29 +862,23 @@ void ScDPGroupTableData::FillGroupValues(vector<SCROW>& rItems, const vector<lon
                 rItems[i] = rCache.GetIdByItemData(nColumn, aItem);
             }
         }
+
+        ++i;
     }
 }
 
 bool ScDPGroupTableData::IsBaseForGroup(long nDim) const
 {
-    for ( ScDPGroupDimensionVec::const_iterator aIter(aGroups.begin()); aIter != aGroups.end(); ++aIter )
-    {
-        const ScDPGroupDimension& rDim = *aIter;
-        if ( rDim.GetSourceDim() == nDim )
-            return true;
-    }
-
-    return false;
+    return std::any_of(aGroups.begin(), aGroups.end(),
+        [&nDim](const ScDPGroupDimension& rDim) { return rDim.GetSourceDim() == nDim; });
 }
 
 long ScDPGroupTableData::GetGroupBase(long nGroupDim) const
 {
-    for ( ScDPGroupDimensionVec::const_iterator aIter(aGroups.begin()); aIter != aGroups.end(); ++aIter )
-    {
-        const ScDPGroupDimension& rDim = *aIter;
-        if ( rDim.GetGroupDim() == nGroupDim )
-            return rDim.GetSourceDim();
-    }
+    auto aIter = std::find_if(aGroups.begin(), aGroups.end(),
+        [&nGroupDim](const ScDPGroupDimension& rDim) { return rDim.GetGroupDim() == nGroupDim; });
+    if (aIter != aGroups.end())
+        return aIter->GetSourceDim();
 
     return -1;      // none
 }
@@ -911,12 +893,10 @@ bool ScDPGroupTableData::IsNumOrDateGroup(long nDimension) const
                pNumGroups[nDimension].IsDateDimension();
     }
 
-    for ( ScDPGroupDimensionVec::const_iterator aIter(aGroups.begin()); aIter != aGroups.end(); ++aIter )
-    {
-        const ScDPGroupDimension& rDim = *aIter;
-        if ( rDim.GetGroupDim() == nDimension )
-            return rDim.IsDateDimension();
-    }
+    auto aIter = std::find_if(aGroups.begin(), aGroups.end(),
+        [&nDimension](const ScDPGroupDimension& rDim) { return rDim.GetGroupDim() == nDimension; });
+    if (aIter != aGroups.end())
+        return aIter->IsDateDimension();
 
     return false;
 }
@@ -924,24 +904,24 @@ bool ScDPGroupTableData::IsNumOrDateGroup(long nDimension) const
 bool ScDPGroupTableData::IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
                                     const ScDPItemData& rBaseData, long nBaseIndex ) const
 {
-    for ( ScDPGroupDimensionVec::const_iterator aIter(aGroups.begin()); aIter != aGroups.end(); ++aIter )
+    auto aIter = std::find_if(aGroups.begin(), aGroups.end(),
+        [&nGroupIndex, &nBaseIndex](const ScDPGroupDimension& rDim) {
+            return rDim.GetGroupDim() == nGroupIndex && rDim.GetSourceDim() == nBaseIndex; });
+    if (aIter != aGroups.end())
     {
         const ScDPGroupDimension& rDim = *aIter;
-        if ( rDim.GetGroupDim() == nGroupIndex && rDim.GetSourceDim() == nBaseIndex )
+        if (rDim.IsDateDimension())
         {
-            if (rDim.IsDateDimension())
-            {
-                return isDateInGroup(rGroupData, rBaseData);
-            }
-            else
-            {
-                // If the item is in a group, only that group is valid.
-                // If the item is not in any group, its own name is valid.
+            return isDateInGroup(rGroupData, rBaseData);
+        }
+        else
+        {
+            // If the item is in a group, only that group is valid.
+            // If the item is not in any group, its own name is valid.
 
-                const ScDPGroupItem* pGroup = rDim.GetGroupForData( rBaseData );
-                return pGroup ? pGroup->GetName().IsCaseInsEqual( rGroupData ) :
-                                rGroupData.IsCaseInsEqual( rBaseData );
-            }
+            const ScDPGroupItem* pGroup = rDim.GetGroupForData( rBaseData );
+            return pGroup ? pGroup->GetName().IsCaseInsEqual( rGroupData ) :
+                            rGroupData.IsCaseInsEqual( rBaseData );
         }
     }
 
@@ -954,9 +934,9 @@ bool ScDPGroupTableData::HasCommonElement( const ScDPItemData& rFirstData, long
 {
     const ScDPGroupDimension* pFirstDim = nullptr;
     const ScDPGroupDimension* pSecondDim = nullptr;
-    for ( ScDPGroupDimensionVec::const_iterator aIter(aGroups.begin()); aIter != aGroups.end(); ++aIter )
+    for ( const auto& rDim : aGroups )
     {
-        const ScDPGroupDimension* pDim = &(*aIter);
+        const ScDPGroupDimension* pDim = &rDim;
         if ( pDim->GetGroupDim() == nFirstIndex )
             pFirstDim = pDim;
         else if ( pDim->GetGroupDim() == nSecondIndex )
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 4f83e326b87f..21f3bf6190c6 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2598,14 +2598,10 @@ bool hasFieldColumn(const vector<ScPivotField>* pRefFields, SCCOL nCol)
     if (!pRefFields)
         return false;
 
-    vector<ScPivotField>::const_iterator itr = pRefFields->begin(), itrEnd = pRefFields->end();
-    for (; itr != itrEnd; ++itr)
-    {
-        if (itr->nCol == nCol)
+    return std::any_of(pRefFields->begin(), pRefFields->end(),
+        [&nCol](const ScPivotField& rField) {
             // This array of fields contains the specified column.
-            return true;
-    }
-    return false;
+            return rField.nCol == nCol; });
 }
 
 class FindByOriginalDim
@@ -2907,10 +2903,8 @@ struct FindInvalidRange
 void setGroupItemsToCache( ScDPCache& rCache, const std::set<ScDPObject*>& rRefs )
 {
     // Go through all referencing pivot tables, and re-fill the group dimension info.
-    std::set<ScDPObject*>::const_iterator itRef = rRefs.begin(), itRefEnd = rRefs.end();
-    for (; itRef != itRefEnd; ++itRef)
+    for (const ScDPObject* pObj : rRefs)
     {
-        const ScDPObject* pObj = *itRef;
         const ScDPSaveData* pSave = pObj->GetSaveData();
         if (!pSave)
             continue;
@@ -3037,10 +3031,8 @@ void ScDPCollection::SheetCaches::updateReference(
         // No caches.
         return;
 
-    RangeIndexType::iterator it = maRanges.begin(), itEnd = maRanges.end();
-    for (; it != itEnd; ++it)
+    for (ScRange& rKeyRange : maRanges)
     {
-        const ScRange& rKeyRange = *it;
         SCCOL nCol1 = rKeyRange.aStart.Col();
         SCROW nRow1 = rKeyRange.aStart.Row();
         SCTAB nTab1 = rKeyRange.aStart.Tab();
@@ -3058,7 +3050,7 @@ void ScDPCollection::SheetCaches::updateReference(
         {
             // range updated.
             ScRange aNew(nCol1, nRow1, nTab1, nCol2, nRow2, nTab2);
-            *it = aNew;
+            rKeyRange = aNew;
         }
     }
 }
@@ -3096,16 +3088,14 @@ void ScDPCollection::SheetCaches::updateCache(const ScRange& rRange, std::set<Sc
 
 bool ScDPCollection::SheetCaches::remove(const ScDPCache* p)
 {
-    CachesType::iterator it = m_Caches.begin(), itEnd = m_Caches.end();
-    for (; it != itEnd; ++it)
+    CachesType::iterator it = std::find_if(m_Caches.begin(), m_Caches.end(),
+        [&p](const CachesType::value_type& rEntry) { return rEntry.second.get() == p; });
+    if (it != m_Caches.end())
     {
-        if (it->second.get() == p)
-        {
-            size_t idx = it->first;
-            m_Caches.erase(it);
-            maRanges[idx].SetInvalid();
-            return true;
-        }
+        size_t idx = it->first;
+        m_Caches.erase(it);
+        maRanges[idx].SetInvalid();
+        return true;
     }
     return false;
 }
@@ -3174,14 +3164,12 @@ void ScDPCollection::NameCaches::updateCache(
 
 bool ScDPCollection::NameCaches::remove(const ScDPCache* p)
 {
-    CachesType::iterator it = m_Caches.begin(), itEnd = m_Caches.end();
-    for (; it != itEnd; ++it)
+    CachesType::iterator it = std::find_if(m_Caches.begin(), m_Caches.end(),
+        [&p](const CachesType::value_type& rEntry) { return rEntry.second.get() == p; });
+    if (it != m_Caches.end())
     {
-        if (it->second.get() == p)
-        {
-            m_Caches.erase(it);
-            return true;
-        }
+        m_Caches.erase(it);
+        return true;
     }
     return false;
 }
@@ -3346,14 +3334,12 @@ void ScDPCollection::DBCaches::updateCache(
 
 bool ScDPCollection::DBCaches::remove(const ScDPCache* p)
 {
-    CachesType::iterator it = m_Caches.begin(), itEnd = m_Caches.end();
-    for (; it != itEnd; ++it)
+    CachesType::iterator it = std::find_if(m_Caches.begin(), m_Caches.end(),
+        [&p](const CachesType::value_type& rEntry) { return rEntry.second.get() == p; });
+    if (it != m_Caches.end())
     {
-        if (it->second.get() == p)
-        {
-            m_Caches.erase(it);
-            return true;
-        }
+        m_Caches.erase(it);
+        return true;
     }
     return false;
 }
@@ -3623,9 +3609,8 @@ void ScDPCollection::DeleteOnTab( SCTAB nTab )
 void ScDPCollection::UpdateReference( UpdateRefMode eUpdateRefMode,
                                          const ScRange& r, SCCOL nDx, SCROW nDy, SCTAB nDz )
 {
-    TablesType::iterator itr = maTables.begin(), itrEnd = maTables.end();
-    for (; itr != itrEnd; ++itr)
-        (*itr)->UpdateReference(eUpdateRefMode, r, nDx, nDy, nDz);
+    for (auto& rxTable : maTables)
+        rxTable->UpdateReference(eUpdateRefMode, r, nDx, nDy, nDz);
 
     // Update the source ranges of the caches.
     maSheetCaches.updateReference(eUpdateRefMode, r, nDx, nDy, nDz);
@@ -3634,10 +3619,9 @@ void ScDPCollection::UpdateReference( UpdateRefMode eUpdateRefMode,
 void ScDPCollection::CopyToTab( SCTAB nOld, SCTAB nNew )
 {
     TablesType aAdded;
-    TablesType::const_iterator it = maTables.begin(), itEnd = maTables.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rxTable : maTables)
     {
-        const ScDPObject& rObj = **it;
+        const ScDPObject& rObj = *rxTable;
         ScRange aOutRange = rObj.GetOutRange();
         if (aOutRange.aStart.Tab() != nOld)
             continue;
@@ -3657,15 +3641,8 @@ void ScDPCollection::CopyToTab( SCTAB nOld, SCTAB nNew )
 
 bool ScDPCollection::RefsEqual( const ScDPCollection& r ) const
 {
-    if (maTables.size() != r.maTables.size())
-        return false;
-
-    TablesType::const_iterator itr = maTables.begin(), itr2 = r.maTables.begin(), itrEnd = maTables.end();
-    for (; itr != itrEnd; ++itr, ++itr2)
-        if (!(*itr)->RefsEqual(**itr2))
-            return false;
-
-    return true;
+    return std::equal(maTables.begin(), maTables.end(), r.maTables.begin(), r.maTables.end(),
+        [](const TablesType::value_type& a, const TablesType::value_type& b) { return a->RefsEqual(*b); });
 }
 
 void ScDPCollection::WriteRefsTo( ScDPCollection& r ) const
@@ -3673,10 +3650,12 @@ void ScDPCollection::WriteRefsTo( ScDPCollection& r ) const
     if ( maTables.size() == r.maTables.size() )
     {
         //TODO: assert equal names?
-        TablesType::const_iterator itr = maTables.begin(), itrEnd = maTables.end();
         TablesType::iterator itr2 = r.maTables.begin();
-        for (; itr != itrEnd; ++itr, ++itr2)
-            (*itr)->WriteRefsTo(**itr2);
+        for (const auto& rxTable : maTables)
+        {
+            rxTable->WriteRefsTo(**itr2);
+            ++itr2;
+        }
     }
     else
     {
@@ -3743,17 +3722,8 @@ OUString ScDPCollection::CreateNewName() const
     for (size_t nAdd = 0; nAdd <= n; ++nAdd)   //  nCount+1 tries
     {
         OUString aNewName = "DataPilot" + OUString::number(1 + nAdd);
-        bool bFound = false;
-        TablesType::const_iterator itr = maTables.begin(), itrEnd = maTables.end();
-        for (; itr != itrEnd; ++itr)
-        {
-            if ((*itr)->GetName() == aNewName)
-            {
-                bFound = true;
-                break;
-            }
-        }
-        if (!bFound)
+        if (std::none_of(maTables.begin(), maTables.end(),
+                         [&aNewName](const TablesType::value_type& rxObj) { return rxObj->GetName() == aNewName; }))
             return aNewName;            // found unused Name
     }
     return OUString();                    // should not happen
@@ -3893,10 +3863,9 @@ void ScDPCollection::RemoveCache(const ScDPCache* pCache)
 void ScDPCollection::GetAllTables(const ScRange& rSrcRange, std::set<ScDPObject*>& rRefs) const
 {
     std::set<ScDPObject*> aRefs;
-    TablesType::const_iterator it = maTables.begin(), itEnd = maTables.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rxTable : maTables)
     {
-        const ScDPObject& rObj = **it;
+        const ScDPObject& rObj = *rxTable;
         if (!rObj.IsSheetData())
             // Source is not a sheet range.
             continue;
@@ -3922,10 +3891,9 @@ void ScDPCollection::GetAllTables(const ScRange& rSrcRange, std::set<ScDPObject*
 void ScDPCollection::GetAllTables(const OUString& rSrcName, std::set<ScDPObject*>& rRefs) const
 {
     std::set<ScDPObject*> aRefs;
-    TablesType::const_iterator it = maTables.begin(), itEnd = maTables.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rxTable : maTables)
     {
-        const ScDPObject& rObj = **it;
+        const ScDPObject& rObj = *rxTable;
         if (!rObj.IsSheetData())
             // Source is not a sheet range.
             continue;
@@ -3953,10 +3921,9 @@ void ScDPCollection::GetAllTables(
     std::set<ScDPObject*>& rRefs) const
 {
     std::set<ScDPObject*> aRefs;
-    TablesType::const_iterator it = maTables.begin(), itEnd = maTables.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rxTable : maTables)
     {
-        const ScDPObject& rObj = **it;
+        const ScDPObject& rObj = *rxTable;
         if (!rObj.IsImportData())
             // Source data is not a database.
             continue;
diff --git a/sc/source/core/data/dpresfilter.cxx b/sc/source/core/data/dpresfilter.cxx
index e1b37f3dfc2d..c4102824fe1f 100644
--- a/sc/source/core/data/dpresfilter.cxx
+++ b/sc/source/core/data/dpresfilter.cxx
@@ -66,15 +66,13 @@ ScDPResultTree::MemberNode::~MemberNode() {}
 void ScDPResultTree::MemberNode::dump(int nLevel) const
 {
     string aIndent(nLevel*2, ' ');
-    ValuesType::const_iterator itVal = maValues.begin(), itValEnd = maValues.end();
-    for (; itVal != itValEnd; ++itVal)
-        cout << aIndent << "value: " << *itVal << endl;
+    for (const auto& rValue : maValues)
+        cout << aIndent << "value: " << rValue << endl;
 
-    DimensionsType::const_iterator it = maChildDimensions.begin(), itEnd = maChildDimensions.end();
-    for (; it != itEnd; ++it)
+    for (const auto& [rName, rxDim] : maChildDimensions)
     {
-        cout << aIndent << "dimension: " << it->first << endl;
-        it->second->dump(nLevel+1);
+        cout << aIndent << "dimension: " << rName << endl;
+        rxDim->dump(nLevel+1);
     }
 }
 #endif
@@ -93,10 +91,8 @@ void ScDPResultTree::add(
     const OUString* pMemName = nullptr;
     MemberNode* pMemNode = mpRoot.get();
 
-    std::vector<ScDPResultFilter>::const_iterator itFilter = rFilters.begin(), itFilterEnd = rFilters.end();
-    for (; itFilter != itFilterEnd; ++itFilter)
+    for (const ScDPResultFilter& filter : rFilters)
     {
-        const ScDPResultFilter& filter = *itFilter;
         if (filter.mbDataLayout)
             continue;
 
diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index ceb9fa8d7227..c5c5139ad170 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -205,10 +205,10 @@ ScDPSaveDimension::ScDPSaveDimension(const ScDPSaveDimension& r) :
     bSubTotalDefault( r.bSubTotalDefault ),
     maSubTotalFuncs( r.maSubTotalFuncs )
 {
-    for (MemberList::const_iterator i=r.maMemberList.begin(); i != r.maMemberList.end() ; ++i)
+    for (const ScDPSaveMember* pMem : r.maMemberList)
     {
-        const OUString& rName =  (*i)->GetName();
-        std::unique_ptr<ScDPSaveMember> pNew(new ScDPSaveMember( **i ));
+        const OUString& rName = pMem->GetName();
+        std::unique_ptr<ScDPSaveMember> pNew(new ScDPSaveMember( *pMem ));
         maMemberList.push_back( pNew.get() );
         maMemberHash[rName] = std::move(pNew);
     }
@@ -248,11 +248,9 @@ bool ScDPSaveDimension::operator== ( const ScDPSaveDimension& r ) const
     if (maMemberHash.size() != r.maMemberHash.size() )
         return false;
 
-    MemberList::const_iterator a=maMemberList.begin();
-    MemberList::const_iterator b=r.maMemberList.begin();
-    for (; a != maMemberList.end() ; ++a, ++b)
-        if (!(**a == **b))
-            return false;
+    if (!std::equal(maMemberList.begin(), maMemberList.end(), r.maMemberList.begin(), r.maMemberList.end(),
+                    [](const ScDPSaveMember* a, const ScDPSaveMember* b) { return *a == *b; }))
+        return false;
 
     if( pReferenceValue && r.pReferenceValue )
     {
@@ -369,18 +367,13 @@ void ScDPSaveDimension::RemoveSubtotalName()
 
 bool ScDPSaveDimension::IsMemberNameInUse(const OUString& rName) const
 {
-    MemberList::const_iterator itr = maMemberList.begin(), itrEnd = maMemberList.end();
-    for (; itr != itrEnd; ++itr)
-    {
-        const ScDPSaveMember* pMem = *itr;
+    return std::any_of(maMemberList.begin(), maMemberList.end(), [&rName](const ScDPSaveMember* pMem) {
         if (rName.equalsIgnoreAsciiCase(pMem->GetName()))
             return true;
 
         const boost::optional<OUString> & pLayoutName = pMem->GetLayoutName();
-        if (pLayoutName && rName.equalsIgnoreAsciiCase(*pLayoutName))
-            return true;
-    }
-    return false;
+        return pLayoutName && rName.equalsIgnoreAsciiCase(*pLayoutName);
+    });
 }
 
 void ScDPSaveDimension::SetLayoutName(const OUString& rName)
@@ -435,10 +428,8 @@ void ScDPSaveDimension::SetCurrentPage( const OUString* pPage )
     // We use member's visibility attribute to filter by page dimension.
 
     // pPage == nullptr -> all members visible.
-    MemberList::iterator it = maMemberList.begin(), itEnd = maMemberList.end();
-    for (; it != itEnd; ++it)
+    for (ScDPSaveMember* pMem : maMemberList)
     {
-        ScDPSaveMember* pMem = *it;
         bool bVisible = !pPage || pMem->GetName() == *pPage;
         pMem->SetIsVisible(bVisible);
     }
@@ -446,13 +437,10 @@ void ScDPSaveDimension::SetCurrentPage( const OUString* pPage )
 
 OUString ScDPSaveDimension::GetCurrentPage() const
 {
-    MemberList::const_iterator it = maMemberList.begin(), itEnd = maMemberList.end();
-    for (; it != itEnd; ++it)
-    {
-        const ScDPSaveMember* pMem = *it;
-        if (pMem->GetIsVisible())
-            return pMem->GetName();
-    }
+    MemberList::const_iterator it = std::find_if(maMemberList.begin(), maMemberList.end(),
+        [](const ScDPSaveMember* pMem) { return pMem->GetIsVisible(); });
+    if (it != maMemberList.end())
+        return (*it)->GetName();
 
     return OUString();
 }
@@ -596,9 +584,8 @@ void ScDPSaveDimension::WriteToSource( const uno::Reference<uno::XInterface>& xD
                         if ( !pSortInfo || pSortInfo->Mode == sheet::DataPilotFieldSortMode::MANUAL )
                             nPosition = 0;
 
-                        for (MemberList::const_iterator i=maMemberList.begin(); i != maMemberList.end() ; ++i)
+                        for (ScDPSaveMember* pMember : maMemberList)
                         {
-                            ScDPSaveMember* pMember = *i;
                             if (!pMember->GetIsVisible())
                                 bHasHiddenMember = true;
                             OUString aMemberName = pMember->GetName();
@@ -626,10 +613,8 @@ void ScDPSaveDimension::WriteToSource( const uno::Reference<uno::XInterface>& xD
 void ScDPSaveDimension::UpdateMemberVisibility(const std::unordered_map<OUString, bool>& rData)
 {
     typedef std::unordered_map<OUString, bool> DataMap;
-    MemberList::iterator itrMem = maMemberList.begin(), itrMemEnd = maMemberList.end();
-    for (; itrMem != itrMemEnd; ++itrMem)
+    for (ScDPSaveMember* pMem : maMemberList)
     {
-        ScDPSaveMember* pMem = *itrMem;
         const OUString& rMemName = pMem->GetName();
         DataMap::const_iterator itr = rData.find(rMemName);
         if (itr != rData.end())
@@ -639,14 +624,8 @@ void ScDPSaveDimension::UpdateMemberVisibility(const std::unordered_map<OUString
 
 bool ScDPSaveDimension::HasInvisibleMember() const
 {
-    MemberList::const_iterator itrMem = maMemberList.begin(), itrMemEnd = maMemberList.end();
-    for (; itrMem != itrMemEnd; ++itrMem)
-    {
-        const ScDPSaveMember* pMem = *itrMem;
-        if (!pMem->GetIsVisible())
-            return true;
-    }
-    return false;
+    return std::any_of(maMemberList.begin(), maMemberList.end(),
+        [](const ScDPSaveMember* pMem) { return !pMem->GetIsVisible(); });
 }
 
 void ScDPSaveDimension::RemoveObsoleteMembers(const MemberSetType& rMembers)
@@ -701,10 +680,8 @@ void ScDPSaveDimension::Dump(int nIndent) const
     cout << aIndent << "    + is data layout: " << (bIsDataLayout ? "yes" : "no") << endl;
     cout << aIndent << "    + is duplicate: " << (bDupFlag ? "yes" : "no") << endl;
 
-    MemberList::const_iterator itMem = maMemberList.begin(), itMemEnd = maMemberList.end();
-    for (; itMem != itMemEnd; ++itMem)
+    for (ScDPSaveMember* pMem : maMemberList)
     {
-        ScDPSaveMember* pMem = *itMem;
         pMem->Dump(nIndent+1);
     }
 
@@ -923,15 +900,14 @@ ScDPSaveDimension* ScDPSaveData::DuplicateDimension(const OUString& rName)
 
 void ScDPSaveData::RemoveDimensionByName(const OUString& rName)
 {
-    for (auto iter = m_DimList.begin(); iter != m_DimList.end(); ++iter)
+    auto iter = std::find_if(m_DimList.begin(), m_DimList.end(),
+        [&rName](const std::unique_ptr<ScDPSaveDimension>& rxDim) {
+            return rxDim->GetName() == rName && !rxDim->IsDataLayout(); });
+    if (iter != m_DimList.end())
     {
-        if ((*iter)->GetName() != rName || (*iter)->IsDataLayout())
-            continue;
-
         m_DimList.erase(iter);
         RemoveDuplicateNameCount(rName);
         DimensionsChanged();
-        return;
     }
 }
 
@@ -947,11 +923,11 @@ ScDPSaveDimension* ScDPSaveData::GetInnermostDimension(DataPilotFieldOrientation
     // return the innermost dimension for the given orientation,
     // excluding data layout dimension
 
-    for (auto iter = m_DimList.rbegin(); iter != m_DimList.rend(); ++iter)
-    {
-        if ((*iter)->GetOrientation() == nOrientation && !(*iter)->IsDataLayout())
-            return iter->get();
-    }
+    auto iter = std::find_if(m_DimList.rbegin(), m_DimList.rend(),
+        [&nOrientation](const std::unique_ptr<ScDPSaveDimension>& rxDim) {
+            return rxDim->GetOrientation() == nOrientation && !rxDim->IsDataLayout(); });
+    if (iter != m_DimList.rend())
+        return iter->get();
 
     return nullptr;
 }
@@ -985,27 +961,23 @@ void ScDPSaveData::SetPosition( ScDPSaveDimension* pDim, long nNew )
 
     DataPilotFieldOrientation nOrient = pDim->GetOrientation();
 
-    for (auto it = m_DimList.begin(); it != m_DimList.end(); ++it)
+    auto it = std::find_if(m_DimList.begin(), m_DimList.end(),
+        [&pDim](const std::unique_ptr<ScDPSaveDimension>& rxDim) { return pDim == rxDim.get(); });
+    if (it != m_DimList.end())
     {
-        if (pDim == it->get())
-        {
-            // Tell vector<unique_ptr> to give up ownership of this element.
-            // Don't delete this instance as it is re-inserted into the
-            // container later.
-            it->release();
-            m_DimList.erase(it);
-            break;
-        }
+        // Tell vector<unique_ptr> to give up ownership of this element.
+        // Don't delete this instance as it is re-inserted into the
+        // container later.
+        it->release();
+        m_DimList.erase(it);
     }
 
-    auto iterInsert = m_DimList.begin();
-    while ( nNew > 0 && iterInsert != m_DimList.end())
-    {
-        if ((*iterInsert)->GetOrientation() == nOrient )
-            --nNew;
-
-        ++iterInsert;
-    }
+    auto iterInsert = std::find_if(m_DimList.begin(), m_DimList.end(),
+        [&nOrient, &nNew](const std::unique_ptr<ScDPSaveDimension>& rxDim) {
+            if (rxDim->GetOrientation() == nOrient )
+                --nNew;
+            return nNew <= 0;
+        });
 
     m_DimList.insert(iterInsert, std::unique_ptr<ScDPSaveDimension>(pDim));
     DimensionsChanged();
@@ -1104,15 +1076,14 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie
         uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
         long nIntCount = xIntDims->getCount();
 
-        auto iter = m_DimList.begin();
-        for (long i = 0; iter != m_DimList.end(); ++iter, ++i)
+        for (const auto& rxDim : m_DimList)
         {
-            OUString aName = (*iter)->GetName();
+            OUString aName = rxDim->GetName();
             OUString aCoreName = ScDPUtil::getSourceDimensionName(aName);
 
             SAL_INFO("sc.core", aName);
 
-            bool bData = (*iter)->IsDataLayout();
+            bool bData = rxDim->IsDataLayout();
 
             //TODO: getByName for ScDPSource, including DataLayoutDimension !!!!!!!!
 
@@ -1139,7 +1110,7 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie
 
                 if (bFound)
                 {
-                    if ((*iter)->GetDupFlag())
+                    if (rxDim->GetDupFlag())
                     {
                         uno::Reference<util::XCloneable> xCloneable(xIntDim, uno::UNO_QUERY);
                         SAL_WARN_IF(!xCloneable.is(), "sc.core", "cannot clone dimension");
@@ -1150,12 +1121,12 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie
                             if (xNewName.is())
                             {
                                 xNewName->setName(aName);
-                                (*iter)->WriteToSource(xNew);
+                                rxDim->WriteToSource(xNew);
                             }
                         }
                     }
                     else
-                        (*iter)->WriteToSource( xIntDim );
+                        rxDim->WriteToSource( xIntDim );
                 }
             }
             SAL_WARN_IF(!bFound, "sc.core", "WriteToSource: Dimension not found: " + aName + ".");
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index 357ab98fbeac..da6c053c9a8c 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -2715,15 +2715,11 @@ bool ScDPGroupCompare::TestIncluded( const ScDPMember& rMember )
         ScDPItemData aMemberData(rMember.FillItemData());
 
         const std::vector<ScDPInitState::Member>& rMemStates = rInitState.GetMembers();
-        std::vector<ScDPInitState::Member>::const_iterator it = rMemStates.begin(), itEnd = rMemStates.end();
-        for (; it != itEnd && bInclude; ++it)
-        {
-            if (pResultData->GetGroupBase(it->mnSrcIndex) == nDimSource)
-            {
-                bInclude = pResultData->IsInGroup(
-                    it->mnNameIndex, it->mnSrcIndex, aMemberData, nDimSource);
-            }
-        }
+        bInclude = std::all_of(rMemStates.begin(), rMemStates.end(),
+            [this, &aMemberData](const ScDPInitState::Member& rMem) {
+                return (pResultData->GetGroupBase(rMem.mnSrcIndex) != nDimSource)
+                    || pResultData->IsInGroup(rMem.mnNameIndex, rMem.mnSrcIndex, aMemberData, nDimSource);
+            });
     }
     else if ( nGroupBase >= 0 )
     {
@@ -2733,18 +2729,13 @@ bool ScDPGroupCompare::TestIncluded( const ScDPMember& rMember )
         //TODO: get array of groups (or indexes) before loop?
         ScDPItemData aMemberData(rMember.FillItemData());
         const std::vector<ScDPInitState::Member>& rMemStates = rInitState.GetMembers();
-        std::vector<ScDPInitState::Member>::const_iterator it = rMemStates.begin(), itEnd = rMemStates.end();
-        for (; it != itEnd && bInclude; ++it)
-        {
-            if (pResultData->GetGroupBase(it->mnSrcIndex) == nGroupBase)
-            {
+        bInclude = std::all_of(rMemStates.begin(), rMemStates.end(),
+            [this, &aMemberData](const ScDPInitState::Member& rMem) {
                 // coverity[copy_paste_error : FALSE] - same base (hierarchy between
                 // the two groups is irrelevant)
-                bInclude = pResultData->HasCommonElement(
-                    it->mnNameIndex, it->mnSrcIndex, aMemberData, nDimSource);
-            }
-
-        }
+                return (pResultData->GetGroupBase(rMem.mnSrcIndex) != nGroupBase)
+                    || pResultData->HasCommonElement(rMem.mnNameIndex, rMem.mnSrcIndex, aMemberData, nDimSource);
+            });
     }
 
     return bInclude;
@@ -3482,10 +3473,9 @@ void ScDPResultDimension::Dump(int nIndent) const
 {
     std::string aIndent(nIndent*2, ' ');
     std::cout << aIndent << "-- dimension '" << GetName() << "'" << std::endl;
-    MemberArray::const_iterator it = maMemberArray.begin(), itEnd = maMemberArray.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rxMember : maMemberArray)
     {
-        const ScDPResultMember* p = it->get();
+        const ScDPResultMember* p = rxMember.get();
         p->Dump(nIndent+1);
     }
 }
@@ -3518,11 +3508,9 @@ void ScDPResultDimension::FillVisibilityData(ScDPResultVisibilityData& rData) co
     if (IsDataLayout())
         return;
 
-    MemberArray::const_iterator itr = maMemberArray.begin(), itrEnd = maMemberArray.end();
-
-    for (;itr != itrEnd; ++itr)
+    for (const auto& rxMember : maMemberArray)
     {
-        ScDPResultMember* pMember = itr->get();
+        ScDPResultMember* pMember = rxMember.get();
         if (pMember->IsValid())
         {
             ScDPItemData aItem(pMember->FillItemData());
@@ -3863,9 +3851,8 @@ void ScDPDataDimension::Dump(int nIndent) const
     std::string aIndent(nIndent*2, ' ');
     std::cout << aIndent << "-- data dimension '"
         << (pResultDimension ? pResultDimension->GetName() : OUString()) << "'" << std::endl;
-    auto it = maMembers.begin(), itEnd = maMembers.end();
-    for (; it != itEnd; ++it)
-        (*it)->Dump(nIndent+1);
+    for (auto& rxMember : maMembers)
+        rxMember->Dump(nIndent+1);
 }
 #endif
 
@@ -3926,10 +3913,8 @@ void ScDPResultVisibilityData::fillFieldFilters(vector<ScDPFilteredCache::Criter
     }
 
     const ScDPDimensions* pDims = mpSource->GetDimensionsObject();
-    for (DimMemberType::const_iterator itr = maDimensions.begin(), itrEnd = maDimensions.end();
-          itr != itrEnd; ++itr)
+    for (const auto& [rDimName, rMem] : maDimensions)
     {
-        const OUString& rDimName = itr->first;
         ScDPFilteredCache::Criterion aCri;
         FieldNameMapType::const_iterator itrField = aFieldNames.find(rDimName);
         if (itrField == aFieldNames.end())
@@ -3943,11 +3928,8 @@ void ScDPResultVisibilityData::fillFieldFilters(vector<ScDPFilteredCache::Criter
         ScDPFilteredCache::GroupFilter* pGrpFilter =
             static_cast<ScDPFilteredCache::GroupFilter*>(aCri.mpFilter.get());
 
-        const VisibleMemberType& rMem = itr->second;
-        for (VisibleMemberType::const_iterator itrMem = rMem.begin(), itrMemEnd = rMem.end();
-              itrMem != itrMemEnd; ++itrMem)
+        for (const ScDPItemData& rMemItem : rMem)
         {
-            const ScDPItemData& rMemItem = *itrMem;
             pGrpFilter->addMatchItem(rMemItem);
         }
 
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index e456e3b8136a..0b3f79e35a0d 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -603,10 +603,9 @@ static long lcl_GetIndexFromName( const OUString& rName, const uno::Sequence<OUS
 void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool &rHasAutoShow)
 {
     const std::vector<long>& rDims = bIsRow ? maRowDims : maColDims;
-    std::vector<long>::const_iterator it = rDims.begin(), itEnd = rDims.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rDimIndex : rDims)
     {
-        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(rDimIndex);
         long nHierarchy = ScDPDimension::getUsedHierarchy();
         if ( nHierarchy >= ScDPHierarchies::getCount() )
             nHierarchy = 0;
@@ -631,13 +630,13 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool
 
             if (bIsRow)
             {
-                rInfo.aRowLevelDims.push_back(*it);
+                rInfo.aRowLevelDims.push_back(rDimIndex);
                 rInfo.aRowDims.push_back(pDim);
                 rInfo.aRowLevels.push_back(pLevel);
             }
             else
             {
-                rInfo.aColLevelDims.push_back(*it);
+                rInfo.aColLevelDims.push_back(rDimIndex);
                 rInfo.aColDims.push_back(pDim);
                 rInfo.aColLevels.push_back(pLevel);
             }
@@ -698,10 +697,9 @@ void ScDPSource::FilterCacheByPageDimensions()
 
     // filter table by page dimensions.
     vector<ScDPFilteredCache::Criterion> aCriteria;
-    vector<long>::const_iterator it = maPageDims.begin(), itEnd = maPageDims.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rDimIndex : maPageDims)
     {
-        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(rDimIndex);
         long nField = pDim->GetDimension();
 
         ScDPMembers* pMems = pDim->GetHierarchiesObject()->getByIndex(0)->
@@ -775,11 +773,9 @@ void ScDPSource::CreateRes_Impl()
     // Go through all data dimensions (i.e. fields) and build their meta data
     // so that they can be passed on to ScDPResultData instance later.
     // TODO: aggregate all of data dimension info into a structure.
-    vector<long>::const_iterator it = maDataDims.begin(), itEnd = maDataDims.end();
-    for (; it != itEnd; ++it)
+    for (const long nDimIndex : maDataDims)
     {
         // Get function for each data field.
-        long nDimIndex = *it;
         ScDPDimension* pDim = GetDimensionsObject()->getByIndex(nDimIndex);
         ScGeneralFunction eUser = pDim->getFunction();
         if (eUser == ScGeneralFunction::AUTO)
@@ -845,11 +841,11 @@ void ScDPSource::CreateRes_Impl()
     // (both in column and row fields). aInitState is filled with the page
     // field selections, they are kept across the data iterator loop.
 
-    for (it = maPageDims.begin(), itEnd = maPageDims.end(); it != itEnd; ++it)
+    for (const auto& rDimIndex : maPageDims)
     {
-        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(rDimIndex);
         if ( pDim->HasSelectedPage() )
-            aInitState.AddMember(*it, GetCache()->GetIdByItemData(*it, pDim->GetSelectedData()));
+            aInitState.AddMember(rDimIndex, GetCache()->GetIdByItemData(rDimIndex, pDim->GetSelectedData()));
     }
 
     // Show grand total columns only when the option is set *and* there is at
@@ -881,9 +877,9 @@ void ScDPSource::CreateRes_Impl()
     pRowResRoot->SetHasElements();
 
     // initialize members object also for all page dimensions (needed for numeric groups)
-    for (it = maPageDims.begin(), itEnd = maPageDims.end(); it != itEnd; ++it)
+    for (const auto& rDimIndex : maPageDims)
     {
-        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(*it);
+        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(rDimIndex);
         long nHierarchy = ScDPDimension::getUsedHierarchy();
         if ( nHierarchy >= ScDPHierarchies::getCount() )
             nHierarchy = 0;
@@ -911,10 +907,7 @@ void ScDPSource::CreateRes_Impl()
 
     FilterCacheByPageDimensions();
 
-    aInfo.aPageDims.reserve(maPageDims.size());
-    for (it = maPageDims.begin(), itEnd = maPageDims.end(); it != itEnd; ++it)
-        aInfo.aPageDims.push_back(*it);
-
+    aInfo.aPageDims  = maPageDims;
     aInfo.pInitState = &aInitState;
     aInfo.pColRoot   = pColResRoot.get();
     aInfo.pRowRoot   = pRowResRoot.get();
@@ -994,10 +987,9 @@ void ScDPSource::FillLevelList( sheet::DataPilotFieldOrientation nOrientation, s
     }
 
     ScDPDimensions* pDims = GetDimensionsObject();
-    std::vector<long>::const_iterator it = pDimIndex->begin(), itEnd = pDimIndex->end();
-    for (; it != itEnd; ++it)
+    for (const auto& rIndex : *pDimIndex)
     {
-        ScDPDimension* pDim = pDims->getByIndex(*it);
+        ScDPDimension* pDim = pDims->getByIndex(rIndex);
         OSL_ENSURE( pDim->getOrientation() == nOrientation, "orientations are wrong" );
 
         ScDPHierarchies* pHiers = pDim->GetHierarchiesObject();
@@ -2354,14 +2346,9 @@ long ScDPMembers::getMinMembers() const
     long nVisCount = 0;
     if (!maMembers.empty())
     {
-        MembersType::const_iterator it = maMembers.begin(), itEnd = maMembers.end();
-        for (; it != itEnd; ++it)
-        {
+        nVisCount = std::count_if(maMembers.begin(), maMembers.end(), [](const rtl::Reference<ScDPMember>& pMbr) {
             //  count only visible with details (default is true for both)
-            const rtl::Reference<ScDPMember>& pMbr = *it;
-            if (!pMbr || (pMbr->isVisible() && pMbr->getShowDetails()))
-                ++nVisCount;
-        }
+            return !pMbr || (pMbr->isVisible() && pMbr->getShowDetails()); });
     }
     else
         nVisCount = nMbrCount;      // default for all
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 251c76905a14..fa7a784fbb4a 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -1417,10 +1417,11 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
     rMark.GetMultiMarkArea( aMarkRange );
 
     SCTAB nTabCount = pDoc->GetTableCount();
-    ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
-    for (; itr != itrEnd && *itr < nTabCount; ++itr)
+    for (const SCTAB nTab : rMark)
     {
-        SCTAB nTab = *itr;
+        if (nTab >= nTabCount)
+            break;
+
         SdrPage* pPage = GetPage(static_cast<sal_uInt16>(nTab));
         if (pPage)
         {
@@ -1540,10 +1541,8 @@ static bool lcl_IsAllInRange( const ::std::vector< ScRangeList >& rRangesVector,
 {
     //  check if every range of rRangesVector is completely in rClipRange
 
-    ::std::vector< ScRangeList >::const_iterator aIt = rRangesVector.begin();
-    for( ;aIt!=rRangesVector.end(); ++aIt )
+    for( const ScRangeList& rRanges : rRangesVector )
     {
-        const ScRangeList& rRanges = *aIt;
         for ( size_t i = 0, nCount = rRanges.size(); i < nCount; i++ )
         {
             const ScRange & rRange = rRanges[ i ];
@@ -1562,10 +1561,8 @@ static bool lcl_MoveRanges( ::std::vector< ScRangeList >& rRangesVector, const S
     bool bChanged = false;
 
     ScRange aErrorRange( ScAddress::UNINITIALIZED );
-    ::std::vector< ScRangeList >::iterator aIt = rRangesVector.begin();
-    for( ;aIt!=rRangesVector.end(); ++aIt )
+    for( ScRangeList& rRanges : rRangesVector )
     {
-        ScRangeList& rRanges = *aIt;
         for ( size_t i = 0, nCount = rRanges.size(); i < nCount; i++ )
         {
             ScRange & rRange = rRanges[ i ];
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index 34a6950cbf76..ecdcfd6deb64 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -287,10 +287,9 @@ bool handleConditionalFormat(ScConditionalFormatList& rCondFormList, const std::
 {
     bool bFound = false;
     bool bAnyCondition = false;
-    for(std::vector<sal_uInt32>::const_iterator itr = rCondFormats.begin();
-            itr != rCondFormats.end() && !bFound; ++itr)
+    for(const auto& rCondFormat : rCondFormats)
     {
-        ScConditionalFormat* pCondForm = rCondFormList.GetFormat(*itr);
+        ScConditionalFormat* pCondForm = rCondFormList.GetFormat(rCondFormat);
         if(!pCondForm)
             continue;
 
@@ -340,6 +339,9 @@ bool handleConditionalFormat(ScConditionalFormatList& rCondFormList, const std::
             pInfo->pIconSet = std::move(aData.pIconSet);
             bFound = true;
         }
+
+        if (bFound)
+            break;
     }
 
     return bAnyCondition;
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 1af4729634f8..e7b9b2eedd04 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -583,10 +583,9 @@ sc::FormulaGroupAreaListener* ScFormulaCellGroup::getAreaListener(
 
 void ScFormulaCellGroup::endAllGroupListening( ScDocument& rDoc )
 {
-    AreaListenersType::iterator it = mpImpl->m_AreaListeners.begin(), itEnd = mpImpl->m_AreaListeners.end();
-    for (; it != itEnd; ++it)
+    for (auto& rEntry : mpImpl->m_AreaListeners)
     {
-        sc::FormulaGroupAreaListener *const pListener = it->second.get();
+        sc::FormulaGroupAreaListener *const pListener = rEntry.second.get();
         ScRange aListenRange = pListener->getListeningRange();
         // This "always listen" special range is never grouped.
         bool bGroupListening = (aListenRange != BCA_LISTEN_ALWAYS);
diff --git a/sc/source/core/data/markdata.cxx b/sc/source/core/data/markdata.cxx
index 7c18face085e..8332746878fa 100644
--- a/sc/source/core/data/markdata.cxx
+++ b/sc/source/core/data/markdata.cxx
@@ -424,13 +424,12 @@ void ScMarkData::ExtendRangeListTables( ScRangeList* pList ) const
     ScRangeList aOldList(*pList);
     pList->RemoveAll();                 //TODO: or skip the existing below
 
-    std::set<SCTAB>::const_iterator it = maTabMarked.begin();
-    for (; it != maTabMarked.end(); ++it)
+    for (const auto& rTab : maTabMarked)
         for ( size_t i=0, nCount = aOldList.size(); i<nCount; i++)
         {
             ScRange aRange = aOldList[ i ];
-            aRange.aStart.SetTab(*it);
-            aRange.aEnd.SetTab(*it);
+            aRange.aStart.SetTab(rTab);
+            aRange.aEnd.SetTab(rTab);
             pList->push_back( aRange );
         }
 }
@@ -598,13 +597,12 @@ bool ScMarkData::HasAnyMultiMarks() const
 void ScMarkData::InsertTab( SCTAB nTab )
 {
     std::set<SCTAB> tabMarked;
-    for (auto itr = maTabMarked.begin(), itrEnd = maTabMarked.end();
-            itr != itrEnd; ++itr)
+    for (const auto& rTab : maTabMarked)
     {
-        if (*itr < nTab)
-            tabMarked.insert(*itr);
+        if (rTab < nTab)
+            tabMarked.insert(rTab);
         else
-            tabMarked.insert(*itr + 1);
+            tabMarked.insert(rTab + 1);
     }
     maTabMarked.swap(tabMarked);
 }
@@ -612,13 +610,12 @@ void ScMarkData::InsertTab( SCTAB nTab )
 void ScMarkData::DeleteTab( SCTAB nTab )
 {
     std::set<SCTAB> tabMarked;
-    for (auto itr = maTabMarked.begin(), itrEnd = maTabMarked.end();
-            itr != itrEnd; ++itr)
+    for (const auto& rTab : maTabMarked)
     {
-        if (*itr < nTab)
-            tabMarked.insert(*itr);
-        else if (*itr > nTab)
-            tabMarked.insert(*itr - 1);
+        if (rTab < nTab)
+            tabMarked.insert(rTab);
+        else if (rTab > nTab)
+            tabMarked.insert(rTab - 1);
     }
     maTabMarked.swap(tabMarked);
 }
diff --git a/sc/source/core/data/olinetab.cxx b/sc/source/core/data/olinetab.cxx
index a8d5146a6a23..a7e66c8f8d55 100644
--- a/sc/source/core/data/olinetab.cxx
+++ b/sc/source/core/data/olinetab.cxx
@@ -143,10 +143,9 @@ ScOutlineArray::ScOutlineArray( const ScOutlineArray& rArray ) :
     for (size_t nLevel = 0; nLevel < nDepth; ++nLevel)
     {
         const ScOutlineCollection& rColl = rArray.aCollections[nLevel];
-        ScOutlineCollection::const_iterator it = rColl.begin(), itEnd = rColl.end();
-        for (; it != itEnd; ++it)
+        for (const auto& rEntry : rColl)
         {
-            const ScOutlineEntry *const pEntry = &it->second;
+            const ScOutlineEntry *const pEntry = &rEntry.second;
             aCollections[nLevel].insert(*pEntry);
         }
     }
@@ -164,15 +163,16 @@ void ScOutlineArray::FindEntry(
     for (size_t nLevel = 0; nLevel < nMaxLevel; ++nLevel) //TODO: Search backwards?
     {
         ScOutlineCollection* pCollect = &aCollections[nLevel];
-        ScOutlineCollection::iterator it = pCollect->begin(), itEnd = pCollect->end();
-        for (; it != itEnd; ++it)
+        size_t nIndex = 0;
+        for (auto& rEntry : *pCollect)
         {
-            ScOutlineEntry *const pEntry = &it->second;
+            ScOutlineEntry *const pEntry = &rEntry.second;
             if (pEntry->GetStart() <= nSearchPos && pEntry->GetEnd() >= nSearchPos)
             {
                 rFindLevel = nLevel + 1; // Next Level (for insertion)
-                rFindIndex = std::distance(pCollect->begin(), it);
+                rFindIndex = nIndex;
             }
+            ++nIndex;
         }
     }
 }
@@ -289,10 +289,9 @@ bool ScOutlineArray::FindTouchedLevel(
     for (size_t nLevel = 0; nLevel < nDepth; ++nLevel)
     {
         const ScOutlineCollection* pCollect = &aCollections[nLevel];
-        ScOutlineCollection::const_iterator it = pCollect->begin(), itEnd = pCollect->end();
-        for (; it != itEnd; ++it)
+        for (const auto& rEntry : *pCollect)
         {
-            const ScOutlineEntry *const pEntry = &it->second;
+            const ScOutlineEntry *const pEntry = &rEntry.second;
             SCCOLROW nStart = pEntry->GetStart();
             SCCOLROW nEnd   = pEntry->GetEnd();
 
@@ -465,13 +464,13 @@ const ScOutlineEntry* ScOutlineArray::GetEntryByPos(size_t nLevel, SCCOLROW nPos
         return nullptr;
 
     const ScOutlineCollection& rColl = aCollections[nLevel];
-    ScOutlineCollection::const_iterator it = rColl.begin(), itEnd = rColl.end();
-    for (; it != itEnd; ++it)
-    {
-        const ScOutlineEntry *const pEntry = &it->second;
-        if (pEntry->GetStart() <= nPos && nPos <= pEntry->GetEnd())
-            return pEntry;
-    }
+    ScOutlineCollection::const_iterator it = std::find_if(rColl.begin(), rColl.end(),
+        [&nPos](const auto& rEntry) {
+            const ScOutlineEntry *const pEntry = &rEntry.second;
+            return pEntry->GetStart() <= nPos && nPos <= pEntry->GetEnd();
+        });
+    if (it != rColl.end())
+        return &it->second;
 
     return nullptr;
 }
@@ -483,15 +482,15 @@ bool ScOutlineArray::GetEntryIndex(size_t nLevel, SCCOLROW nPos, size_t& rnIndex
 
     // Found entry contains passed position
     const ScOutlineCollection& rColl = aCollections[nLevel];
-    ScOutlineCollection::const_iterator it = rColl.begin(), itEnd = rColl.end();
-    for (; it != itEnd; ++it)
+    ScOutlineCollection::const_iterator it = std::find_if(rColl.begin(), rColl.end(),
+        [&nPos](const auto& rEntry) {
+            const ScOutlineEntry *const p = &rEntry.second;
+            return p->GetStart() <= nPos && nPos <= p->GetEnd();
+        });
+    if (it != rColl.end())
     {
-        const ScOutlineEntry *const p = &it->second;
-        if (p->GetStart() <= nPos && nPos <= p->GetEnd())
-        {
-            rnIndex = std::distance(rColl.begin(), it);
-            return true;
-        }
+        rnIndex = std::distance(rColl.begin(), it);
+        return true;
     }
     return false;
 }
@@ -504,15 +503,15 @@ bool ScOutlineArray::GetEntryIndexInRange(
 
     // Found entry will be completely inside of passed range
     const ScOutlineCollection& rColl = aCollections[nLevel];
-    ScOutlineCollection::const_iterator it = rColl.begin(), itEnd = rColl.end();
-    for (; it != itEnd; ++it)
+    ScOutlineCollection::const_iterator it = std::find_if(rColl.begin(), rColl.end(),
+        [&nBlockStart, &nBlockEnd](const auto& rEntry) {
+            const ScOutlineEntry *const p = &rEntry.second;
+            return nBlockStart <= p->GetStart() && p->GetEnd() <= nBlockEnd;
+        });
+    if (it != rColl.end())
     {
-        const ScOutlineEntry *const p = &it->second;
-        if (nBlockStart <= p->GetStart() && p->GetEnd() <= nBlockEnd)
-        {
-            rnIndex = std::distance(rColl.begin(), it);
-            return true;
-        }
+        rnIndex = std::distance(rColl.begin(), it);
+        return true;
     }
     return false;
 }
@@ -530,19 +529,19 @@ void ScOutlineArray::SetVisibleBelow(
     for (size_t nSubLevel = nLevel+1; nSubLevel < nDepth; ++nSubLevel)
     {
         ScOutlineCollection& rColl = aCollections[nSubLevel];
-        ScOutlineCollection::iterator it = rColl.begin(), itEnd = rColl.end();
-        for (; it != itEnd; ++it)
+        size_t nPos = 0;
+        for (auto& rEntry : rColl)
         {
-            ScOutlineEntry *const p = &it->second;
+            ScOutlineEntry *const p = &rEntry.second;
             if (p->GetStart() >= nStart && p->GetEnd() <= nEnd)
             {
                 p->SetVisible(bValue);
                 if (bSkipHidden && !p->IsHidden())
                 {
-                    size_t nPos = std::distance(rColl.begin(), it);
                     SetVisibleBelow(nSubLevel, nPos, bValue, true);
                 }
             }
+            ++nPos;
         }
 
         if (bSkipHidden)
@@ -570,10 +569,9 @@ void ScOutlineArray::ExtendBlock(size_t nLevel, SCCOLROW& rBlkStart, SCCOLROW& r
         return;
 
     const ScOutlineCollection& rColl = aCollections[nLevel];
-    ScOutlineCollection::const_iterator it = rColl.begin(), itEnd = rColl.end();
-    for (; it != itEnd; ++it)
+    for (const auto& rEntry : rColl)
     {
-        const ScOutlineEntry *const pEntry = &it->second;
+        const ScOutlineEntry *const pEntry = &rEntry.second;
         SCCOLROW nStart = pEntry->GetStart();
         SCCOLROW nEnd   = pEntry->GetEnd();
 
diff --git a/sc/source/core/data/pivot2.cxx b/sc/source/core/data/pivot2.cxx
index 7fca2b376c05..03c3e16259be 100644
--- a/sc/source/core/data/pivot2.cxx
+++ b/sc/source/core/data/pivot2.cxx
@@ -122,10 +122,9 @@ void ScPivotParam::SetLabelData(const ScDPLabelDataVector& rVector)
 {
     ScDPLabelDataVector aNewArray;
     aNewArray.reserve(rVector.size());
-    ScDPLabelDataVector::const_iterator it;
-    for (it = rVector.begin(); it != rVector.end(); ++it)
+    for (const auto& rxData : rVector)
     {
-        aNewArray.push_back(std::make_unique<ScDPLabelData>(**it));
+        aNewArray.push_back(std::make_unique<ScDPLabelData>(*rxData));
     }
     maLabelArray.swap(aNewArray);
 }
diff --git a/sc/source/core/data/stlpool.cxx b/sc/source/core/data/stlpool.cxx
index 7097bbcb79e8..b2ac20625ec2 100644
--- a/sc/source/core/data/stlpool.cxx
+++ b/sc/source/core/data/stlpool.cxx
@@ -410,11 +410,10 @@ ScStyleSheet* ScStyleSheetPool::FindCaseIns( const OUString& rName, SfxStyleFami
 {
     CaseInsensitiveNamePredicate aPredicate(rName, eFam);
     std::vector<unsigned> aFoundPositions = GetIndexedStyleSheets().FindPositionsByPredicate(aPredicate);
-    std::vector<unsigned>::const_iterator it = aFoundPositions.begin();
 
-    for (/**/;it != aFoundPositions.end(); ++it)
+    for (const auto& rPos : aFoundPositions)
     {
-        SfxStyleSheetBase *pFound = GetStyleSheetByPositionInIndex(*it);
+        SfxStyleSheetBase *pFound = GetStyleSheetByPositionInIndex(rPos);
         // we do not know what kind of sheets we have.
         if (pFound->isScStyleSheet())
             return static_cast<ScStyleSheet*>(pFound);
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index a39376aaa390..7c5555c9f679 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1720,12 +1720,12 @@ void ScTable::UpdateReference(
         SCROW nERow = 0;
         bool bRecalcPages = false;
 
-        for ( ScRangeVec::iterator aIt = aPrintRanges.begin(), aEnd = aPrintRanges.end(); aIt != aEnd; ++aIt )
+        for ( auto& rPrintRange : aPrintRanges )
         {
-            nSCol = aIt->aStart.Col();
-            nSRow = aIt->aStart.Row();
-            nECol = aIt->aEnd.Col();
-            nERow = aIt->aEnd.Row();
+            nSCol = rPrintRange.aStart.Col();
+            nSRow = rPrintRange.aStart.Row();
+            nECol = rPrintRange.aEnd.Col();
+            nERow = rPrintRange.aEnd.Row();
 
             // do not try to modify sheet index of print range
             if ( ScRefUpdate::Update( pDocument, eUpdateRefMode,
@@ -1733,7 +1733,7 @@ void ScTable::UpdateReference(
                                       nDx,nDy,0,
                                       nSCol,nSRow,nSTab, nECol,nERow,nETab ) )
             {
-                *aIt = ScRange( nSCol, nSRow, 0, nECol, nERow, 0 );
+                rPrintRange = ScRange( nSCol, nSRow, 0, nECol, nERow, 0 );
                 bRecalcPages = true;
             }
         }
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 36c6b531ba46..65d87fb28162 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -586,15 +586,14 @@ void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCRO
     ScRange aNewRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
     bool bSameDoc = pDocument->GetStyleSheetPool() == pTable->pDocument->GetStyleSheetPool();
 
-    for(ScConditionalFormatList::const_iterator itr = pTable->mpCondFormatList->begin(),
-            itrEnd = pTable->mpCondFormatList->end(); itr != itrEnd; ++itr)
+    for(const auto& rxCondFormat : *pTable->mpCondFormatList)
     {
-        const ScRangeList& rCondFormatRange = (*itr)->GetRange();
+        const ScRangeList& rCondFormatRange = rxCondFormat->GetRange();
         if(!rCondFormatRange.Intersects( aOldRange ))
             continue;
 
         ScRangeList aIntersectedRange = rCondFormatRange.GetIntersectedRange(aOldRange);
-        std::unique_ptr<ScConditionalFormat> pNewFormat = (*itr)->Clone(pDocument);
+        std::unique_ptr<ScConditionalFormat> pNewFormat = rxCondFormat->Clone(pDocument);
 
         pNewFormat->SetRange(aIntersectedRange);
         sc::RefUpdateContext aRefCxt(*pDocument);
@@ -605,25 +604,24 @@ void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCRO
         aRefCxt.mnTabDelta = nTab - pTable->nTab;
         pNewFormat->UpdateReference(aRefCxt, true);
 
-        if (bSameDoc && pTable->nTab == nTab && CheckAndDeduplicateCondFormat(pDocument, mpCondFormatList->GetFormat((*itr)->GetKey()), pNewFormat.get(), nTab))
+        if (bSameDoc && pTable->nTab == nTab && CheckAndDeduplicateCondFormat(pDocument, mpCondFormatList->GetFormat(rxCondFormat->GetKey()), pNewFormat.get(), nTab))
         {
             continue;
         }
         sal_uLong nMax = 0;
         bool bDuplicate = false;
-        for(ScConditionalFormatList::const_iterator itrCond = mpCondFormatList->begin();
-                itrCond != mpCondFormatList->end(); ++itrCond)
+        for(const auto& rxCond : *mpCondFormatList)
         {
             // Check if there is the same format in the destination
             // If there is, then simply expand its range
-            if (CheckAndDeduplicateCondFormat(pDocument, (*itrCond).get(), pNewFormat.get(), nTab))
+            if (CheckAndDeduplicateCondFormat(pDocument, rxCond.get(), pNewFormat.get(), nTab))
             {
                 bDuplicate = true;
                 break;
             }
 
-            if ((*itrCond)->GetKey() > nMax)
-                nMax = (*itrCond)->GetKey();
+            if (rxCond->GetKey() > nMax)
+                nMax = rxCond->GetKey();
         }
         // Do not add duplicate entries
         if (bDuplicate)
@@ -1662,14 +1660,11 @@ CommentCaptionState ScTable::GetAllNoteCaptionsState(const ScRange& rRange, std:
         {
             aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes);
 
-            for(std::vector<sc::NoteEntry>::const_iterator itr = rNotes.begin(),
-                         itrEnd = rNotes.end(); itr != itrEnd; ++itr)
-            {
-                if ( bIsFirstNoteShownState != itr->mpNote->IsCaptionShown())  // compare the first note caption with others
-                {
-                    return CommentCaptionState::MIXED;
-                }
-            }
+            bool bIsMixedState = std::any_of(rNotes.begin(), rNotes.end(), [bIsFirstNoteShownState](const sc::NoteEntry& rNote) {
+                // compare the first note caption with others
+                return bIsFirstNoteShownState != rNote.mpNote->IsCaptionShown(); });
+            if (bIsMixedState)
+                return CommentCaptionState::MIXED;
         }
     }
     return bIsFirstNoteShownState ? CommentCaptionState::ALLSHOWN : CommentCaptionState::ALLHIDDEN;
@@ -2173,10 +2168,9 @@ void ScTable::FindMaxRotCol( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCC
                     ScStyleSheetPool* pStylePool = pDocument->GetStyleSheetPool();
                     if (mpCondFormatList && pStylePool && !rCondFormatData.empty())
                     {
-                        for(std::vector<sal_uInt32>::const_iterator itr = rCondFormatData.begin(), itrEnd = rCondFormatData.end();
-                                itr != itrEnd; ++itr)
+                        for(const auto& rItem : rCondFormatData)
                         {
-                            const ScConditionalFormat* pFormat = mpCondFormatList->GetFormat(*itr);
+                            const ScConditionalFormat* pFormat = mpCondFormatList->GetFormat(rItem);
                             if ( pFormat )
                             {
                                 size_t nEntryCount = pFormat->size();
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index eb2d1d9c4857..055c55fc14ba 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -359,10 +359,9 @@ public:
         RowsType aRows2;
         aRows2.reserve(rRows.size());
 
-        std::vector<SCCOLROW>::const_iterator it = rIndices.begin(), itEnd = rIndices.end();
-        for (; it != itEnd; ++it)
+        for (const auto& rIndex : rIndices)
         {
-            size_t nPos = *it - nStart; // switch to an offset to top row.
+            size_t nPos = rIndex - nStart; // switch to an offset to top row.
             aRows2.push_back(rRows[nPos]);
             aOrderIndices2.push_back(maOrderIndices[nPos]);
         }
@@ -958,11 +957,10 @@ void ScTable::SortReorderByColumn(
         std::vector<sc::AreaListener> aAreaListeners = pDocument->GetBASM()->GetAllListeners(
                 aMoveRange, sc::OneColumnInsideArea);
         {
-            std::vector<sc::AreaListener>::iterator it = aAreaListeners.begin(), itEnd = aAreaListeners.end();
-            for (; it != itEnd; ++it)
+            for (auto& rAreaListener : aAreaListeners)
             {
-                pDocument->EndListeningArea(it->maArea, it->mbGroupListening, it->mpListener);
-                aListeners.push_back( it->mpListener);
+                pDocument->EndListeningArea(rAreaListener.maArea, rAreaListener.mbGroupListening, rAreaListener.mpListener);
+                aListeners.push_back( rAreaListener.mpListener);
             }
         }
 
@@ -976,17 +974,16 @@ void ScTable::SortReorderByColumn(
 
         // Re-start area listeners on the reordered columns.
         {
-            std::vector<sc::AreaListener>::iterator it = aAreaListeners.begin(), itEnd = aAreaListeners.end();
-            for (; it != itEnd; ++it)
+            for (auto& rAreaListener : aAreaListeners)
             {
-                ScRange aNewRange = it->maArea;
+                ScRange aNewRange = rAreaListener.maArea;
                 sc::ColRowReorderMapType::const_iterator itCol = aColMap.find( aNewRange.aStart.Col());
                 if (itCol != aColMap.end())
                 {
                     aNewRange.aStart.SetCol( itCol->second);
                     aNewRange.aEnd.SetCol( itCol->second);
                 }
-                pDocument->StartListeningArea(aNewRange, it->mbGroupListening, it->mpListener);
+                pDocument->StartListeningArea(aNewRange, rAreaListener.mbGroupListening, rAreaListener.mpListener);
             }
         }
     }
@@ -1103,17 +1100,16 @@ void ScTable::SortReorderByRow(
                 sc::toSpanArrayWithValue<SCROW,const ScPatternAttr*,PatternSpan>(
                     aSortedCols[i].get()->maPatterns);
 
-            std::vector<PatternSpan>::iterator it = aSpans.begin(), itEnd = aSpans.end();
-            for (; it != itEnd; ++it)
+            for (const auto& rSpan : aSpans)
             {
-                assert(it->mpPattern); // should never be NULL.
-                pDocument->GetPool()->Put(*it->mpPattern);
+                assert(rSpan.mpPattern); // should never be NULL.
+                pDocument->GetPool()->Put(*rSpan.mpPattern);
             }
 
-            for (it = aSpans.begin(); it != itEnd; ++it)
+            for (const auto& rSpan : aSpans)
             {
-                aCol[nThisCol].SetPatternArea(it->mnRow1, it->mnRow2, *it->mpPattern);
-                pDocument->GetPool()->Remove(*it->mpPattern);
+                aCol[nThisCol].SetPatternArea(rSpan.mnRow1, rSpan.mnRow2, *rSpan.mpPattern);
+                pDocument->GetPool()->Remove(*rSpan.mpPattern);
             }
         }
 
@@ -1132,16 +1128,13 @@ void ScTable::SortReorderByRow(
         std::vector<sc::RowSpan> aSpans =
             sc::toSpanArray<SCROW,sc::RowSpan>(aRowFlags.maRowsHidden, nRow1);
 
-        std::vector<sc::RowSpan>::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
-        for (; it != itEnd; ++it)
-            SetRowHidden(it->mnRow1, it->mnRow2, true);
+        for (const auto& rSpan : aSpans)
+            SetRowHidden(rSpan.mnRow1, rSpan.mnRow2, true);
 
         aSpans = sc::toSpanArray<SCROW,sc::RowSpan>(aRowFlags.maRowsFiltered, nRow1);
 
-        it = aSpans.begin();
-        itEnd = aSpans.end();
-        for (; it != itEnd; ++it)
-            SetRowFiltered(it->mnRow1, it->mnRow2, true);
+        for (const auto& rSpan : aSpans)
+            SetRowFiltered(rSpan.mnRow1, rSpan.mnRow2, true);
     }
 
     // Notify the cells' listeners to (re-)start listening.
@@ -1185,13 +1178,12 @@ void ScTable::SortReorderByRowRefUpdate(
                 aMoveRange, sc::AreaInsideOrOverlap, sc::ListenerGroupType::Group);
 
         {
-            std::vector<sc::AreaListener>::iterator it = aGrpListeners.begin(), itEnd = aGrpListeners.end();
-            for (; it != itEnd; ++it)
+            for (auto& rGrpListener : aGrpListeners)
             {
-                assert(it->mbGroupListening);
-                SvtListener* pGrpLis = it->mpListener;
+                assert(rGrpListener.mbGroupListening);
+                SvtListener* pGrpLis = rGrpListener.mpListener;
                 pGrpLis->Query(aQuery);
-                pDocument->EndListeningArea(it->maArea, it->mbGroupListening, pGrpLis);
+                pDocument->EndListeningArea(rGrpListener.maArea, rGrpListener.mbGroupListening, pGrpLis);
             }
         }
 
@@ -1305,17 +1297,16 @@ void ScTable::SortReorderByRowRefUpdate(
                 sc::toSpanArrayWithValue<SCROW,const ScPatternAttr*,PatternSpan>(
                     aSortedCols[i].get()->maPatterns);
 
-            std::vector<PatternSpan>::iterator it = aSpans.begin(), itEnd = aSpans.end();
-            for (; it != itEnd; ++it)
+            for (const auto& rSpan : aSpans)
             {
-                assert(it->mpPattern); // should never be NULL.
-                pDocument->GetPool()->Put(*it->mpPattern);
+                assert(rSpan.mpPattern); // should never be NULL.
+                pDocument->GetPool()->Put(*rSpan.mpPattern);
             }
 
-            for (it = aSpans.begin(); it != itEnd; ++it)
+            for (const auto& rSpan : aSpans)
             {
-                aCol[nThisCol].SetPatternArea(it->mnRow1, it->mnRow2, *it->mpPattern);
-                pDocument->GetPool()->Remove(*it->mpPattern);
+                aCol[nThisCol].SetPatternArea(rSpan.mnRow1, rSpan.mnRow2, *rSpan.mpPattern);
+                pDocument->GetPool()->Remove(*rSpan.mpPattern);
             }
         }
 
@@ -1334,16 +1325,13 @@ void ScTable::SortReorderByRowRefUpdate(
         std::vector<sc::RowSpan> aSpans =
             sc::toSpanArray<SCROW,sc::RowSpan>(aRowFlags.maRowsHidden, nRow1);
 
-        std::vector<sc::RowSpan>::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
-        for (; it != itEnd; ++it)
-            SetRowHidden(it->mnRow1, it->mnRow2, true);
+        for (const auto& rSpan : aSpans)
+            SetRowHidden(rSpan.mnRow1, rSpan.mnRow2, true);
 
         aSpans = sc::toSpanArray<SCROW,sc::RowSpan>(aRowFlags.maRowsFiltered, nRow1);
 
-        it = aSpans.begin();
-        itEnd = aSpans.end();
-        for (; it != itEnd; ++it)
-            SetRowFiltered(it->mnRow1, it->mnRow2, true);
+        for (const auto& rSpan : aSpans)
+            SetRowFiltered(rSpan.mnRow1, rSpan.mnRow2, true);
     }
 
     // Set up row reorder map (for later broadcasting of reference updates).
@@ -1368,11 +1356,10 @@ void ScTable::SortReorderByRowRefUpdate(
     std::vector<sc::AreaListener> aAreaListeners = pDocument->GetBASM()->GetAllListeners(
             aMoveRange, sc::OneRowInsideArea);
     {
-        std::vector<sc::AreaListener>::iterator it = aAreaListeners.begin(), itEnd = aAreaListeners.end();
-        for (; it != itEnd; ++it)
+        for (auto& rAreaListener : aAreaListeners)
         {
-            pDocument->EndListeningArea(it->maArea, it->mbGroupListening, it->mpListener);
-            aListeners.push_back( it->mpListener);
+            pDocument->EndListeningArea(rAreaListener.maArea, rAreaListener.mbGroupListening, rAreaListener.mpListener);
+            aListeners.push_back( rAreaListener.mpListener);
         }
     }
 
@@ -1398,16 +1385,12 @@ void ScTable::SortReorderByRowRefUpdate(
 
     std::for_each(aListeners.begin(), aListeners.end(), FormulaGroupPosCollector(aFormulaGroupPos));
     const sc::RefQueryFormulaGroup::TabsType& rGroupTabs = aFormulaGroupPos.getAllPositions();
-    sc::RefQueryFormulaGroup::TabsType::const_iterator itGroupTab = rGroupTabs.begin(), itGroupTabEnd = rGroupTabs.end();
-    for (; itGroupTab != itGroupTabEnd; ++itGroupTab)
+    for (const auto& [rTab, rCols] : rGroupTabs)
     {
-        const sc::RefQueryFormulaGroup::ColsType& rCols = itGroupTab->second;
-        sc::RefQueryFormulaGroup::ColsType::const_iterator itCol = rCols.begin(), itColEnd = rCols.end();
-        for (; itCol != itColEnd; ++itCol)
+        for (const auto& [nCol, rCol] : rCols)
         {
-            const sc::RefQueryFormulaGroup::ColType& rCol = itCol->second;
             std::vector<SCROW> aBounds(rCol);
-            pDocument->UnshareFormulaCells(itGroupTab->first, itCol->first, aBounds);
+            pDocument->UnshareFormulaCells(rTab, nCol, aBounds);
         }
     }
 
@@ -1416,28 +1399,23 @@ void ScTable::SortReorderByRowRefUpdate(
     std::for_each(aListeners.begin(), aListeners.end(), aFunc);
 
     // Re-group formulas in affected columns.
-    for (itGroupTab = rGroupTabs.begin(); itGroupTab != itGroupTabEnd; ++itGroupTab)
+    for (const auto& [rTab, rCols] : rGroupTabs)
     {
-        const sc::RefQueryFormulaGroup::ColsType& rCols = itGroupTab->second;
-        sc::RefQueryFormulaGroup::ColsType::const_iterator itCol = rCols.begin(), itColEnd = rCols.end();
-        for (; itCol != itColEnd; ++itCol)
-            pDocument->RegroupFormulaCells(itGroupTab->first, itCol->first);
+        for (const auto& rEntry : rCols)
+            pDocument->RegroupFormulaCells(rTab, rEntry.first);
     }
 
     // Re-start area listeners on the reordered rows.
+    for (const auto& rAreaListener : aAreaListeners)
     {
-        std::vector<sc::AreaListener>::iterator it = aAreaListeners.begin(), itEnd = aAreaListeners.end();
-        for (; it != itEnd; ++it)
+        ScRange aNewRange = rAreaListener.maArea;
+        sc::ColRowReorderMapType::const_iterator itRow = aRowMap.find( aNewRange.aStart.Row());
+        if (itRow != aRowMap.end())
         {
-            ScRange aNewRange = it->maArea;
-            sc::ColRowReorderMapType::const_iterator itRow = aRowMap.find( aNewRange.aStart.Row());
-            if (itRow != aRowMap.end())
-            {
-                aNewRange.aStart.SetRow( itRow->second);
-                aNewRange.aEnd.SetRow( itRow->second);
-            }
-            pDocument->StartListeningArea(aNewRange, it->mbGroupListening, it->mpListener);
+            aNewRange.aStart.SetRow( itRow->second);
+            aNewRange.aEnd.SetRow( itRow->second);
         }
+        pDocument->StartListeningArea(aNewRange, rAreaListener.mbGroupListening, rAreaListener.mpListener);
     }
 
     // Re-group columns in the sorted range too.
@@ -1893,13 +1871,10 @@ void ScTable::RemoveSubTotals( ScSubTotalParam& rParam )
 
     auto& aRows = aFunc.aRemoved;
 
-    auto it = aRows.rbegin(), itEnd = aRows.rend();
-    for (; it != itEnd; ++it)
-    {
-        SCROW nRow = *it;
-        RemoveRowBreak(nRow+1, false, true);
-        pDocument->DeleteRow(0, nTab, MAXCOL, nTab, nRow, 1);
-    }
+    std::for_each(aRows.rbegin(), aRows.rend(), [this](const SCROW nRow) {
+            RemoveRowBreak(nRow+1, false, true);
+            pDocument->DeleteRow(0, nTab, MAXCOL, nTab, nRow, 1);
+        });
 
     rParam.nRow2 -= aRows.size();
 }
@@ -2051,16 +2026,8 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam )
                     if ( bChanged && bTestPrevSub )
                     {
                         // No group change on rows that will contain subtotal formulas
-                        for ( ::std::vector< RowEntry >::const_iterator
-                                iEntry( aRowVector.begin());
-                                iEntry != aRowVector.end(); ++iEntry)
-                        {
-                            if ( iEntry->nDestRow == nRow )
-                            {
-                                bChanged = false;
-                                break;
-                            }
-                        }
+                        bChanged = std::none_of(aRowVector.begin(), aRowVector.end(),
+                            [&nRow](const RowEntry& rEntry) { return rEntry.nDestRow == nRow; });
                     }
                 }
                 if ( bChanged )
@@ -2078,18 +2045,16 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam )
 
                     if (bSpaceLeft)
                     {
-                        for ( ::std::vector< RowEntry >::iterator iMove(
-                                    aRowVector.begin() );
-                                iMove != aRowVector.end(); ++iMove)
+                        for ( auto& rRowEntry : aRowVector)
                         {
-                            if ( aRowEntry.nDestRow <= iMove->nSubStartRow )
-                                ++iMove->nSubStartRow;
-                            if ( aRowEntry.nDestRow <= iMove->nDestRow )
-                                ++iMove->nDestRow;
-                            if ( aRowEntry.nDestRow <= iMove->nFuncStart )
-                                ++iMove->nFuncStart;
-                            if ( aRowEntry.nDestRow <= iMove->nFuncEnd )
-                                ++iMove->nFuncEnd;
+                            if ( aRowEntry.nDestRow <= rRowEntry.nSubStartRow )
+                                ++rRowEntry.nSubStartRow;
+                            if ( aRowEntry.nDestRow <= rRowEntry.nDestRow )
+                                ++rRowEntry.nDestRow;
+                            if ( aRowEntry.nDestRow <= rRowEntry.nFuncStart )
+                                ++rRowEntry.nFuncStart;
+                            if ( aRowEntry.nDestRow <= rRowEntry.nFuncEnd )
+                                ++rRowEntry.nFuncEnd;
                         }
                         // collect formula positions
                         aRowVector.push_back( aRowEntry );
@@ -2130,11 +2095,10 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam )
         SCROW nGlobalStartFunc = aRowVector[0].nFuncStart;
         SCROW nGlobalEndRow = 0;
         SCROW nGlobalEndFunc = 0;
-        for (::std::vector< RowEntry >::const_iterator iEntry(aRowVector.begin());
-             iEntry != aRowVector.end(); ++iEntry)
+        for (const auto& rRowEntry : aRowVector)
         {
-            nGlobalEndRow = (nGlobalEndRow < iEntry->nDestRow) ? iEntry->nDestRow : nGlobalEndRow;
-            nGlobalEndFunc = (nGlobalEndFunc < iEntry->nFuncEnd) ? iEntry->nFuncEnd : nGlobalEndRow;
+            nGlobalEndRow = (nGlobalEndRow < rRowEntry.nDestRow) ? rRowEntry.nDestRow : nGlobalEndRow;
+            nGlobalEndFunc = (nGlobalEndFunc < rRowEntry.nFuncEnd) ? rRowEntry.nFuncEnd : nGlobalEndRow;
         }
 
         for (sal_uInt16 nLevel = 0; nLevel<nLevelCount; nLevel++)
@@ -2184,18 +2148,17 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam )
     aRef.InitFlags();
     aRef.Ref1.SetAbsTab(nTab);
     aRef.Ref2.SetAbsTab(nTab);
-    for ( ::std::vector< RowEntry >::const_iterator iEntry( aRowVector.begin());
-            iEntry != aRowVector.end(); ++iEntry)
+    for (const auto& rRowEntry : aRowVector)
     {
-        SCCOL nResCount         = rParam.nSubTotals[iEntry->nGroupNo];
-        SCCOL* nResCols         = rParam.pSubTotals[iEntry->nGroupNo];
-        ScSubTotalFunc* pResFunc = rParam.pFunctions[iEntry->nGroupNo];
+        SCCOL nResCount         = rParam.nSubTotals[rRowEntry.nGroupNo];
+        SCCOL* nResCols         = rParam.pSubTotals[rRowEntry.nGroupNo];
+        ScSubTotalFunc* pResFunc = rParam.pFunctions[rRowEntry.nGroupNo];
         for ( SCCOL nResult=0; nResult < nResCount; ++nResult )
         {
             aRef.Ref1.SetAbsCol(nResCols[nResult]);
-            aRef.Ref1.SetAbsRow(iEntry->nFuncStart);
+            aRef.Ref1.SetAbsRow(rRowEntry.nFuncStart);
             aRef.Ref2.SetAbsCol(nResCols[nResult]);
-            aRef.Ref2.SetAbsRow(iEntry->nFuncEnd);
+            aRef.Ref2.SetAbsRow(rRowEntry.nFuncEnd);
 
             ScTokenArray aArr;
             aArr.AddOpCode( ocSubTotal );
@@ -2206,16 +2169,16 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam )
             aArr.AddOpCode( ocClose );
             aArr.AddOpCode( ocStop );
             ScFormulaCell* pCell = new ScFormulaCell(
-                pDocument, ScAddress(nResCols[nResult], iEntry->nDestRow, nTab), aArr);
+                pDocument, ScAddress(nResCols[nResult], rRowEntry.nDestRow, nTab), aArr);
             if ( rParam.bIncludePattern )
                 pCell->SetNeedNumberFormat(true);
 
-            SetFormulaCell(nResCols[nResult], iEntry->nDestRow, pCell);
-            if ( nResCols[nResult] != nGroupCol[iEntry->nGroupNo] )
+            SetFormulaCell(nResCols[nResult], rRowEntry.nDestRow, pCell);
+            if ( nResCols[nResult] != nGroupCol[rRowEntry.nGroupNo] )
             {
-                ApplyStyle( nResCols[nResult], iEntry->nDestRow, pStyle );
+                ApplyStyle( nResCols[nResult], rRowEntry.nDestRow, pStyle );
 

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list