diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFPatchTransfer/VoFPatchTransfer.C b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFPatchTransfer/VoFPatchTransfer.C
index b3a646e93b9f96a78afb8932c827a3e2f8706018..c6be4477da0fd630ad58131b71886823f89b92f4 100644
--- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFPatchTransfer/VoFPatchTransfer.C
+++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFPatchTransfer/VoFPatchTransfer.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -85,9 +85,8 @@ VoFPatchTransfer::VoFPatchTransfer
         Info<< "        applying to patches:" << nl;
 
         label pidi = 0;
-        forAllConstIter(labelHashSet, patchSet, iter)
+        for (const label patchi : patchSet)
         {
-            const label patchi = iter.key();
             patchIDs_[pidi++] = patchi;
             Info<< "            " << pbm[patchi].name() << endl;
         }
diff --git a/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C b/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C
index 58b2e3468e7f0e4fa0c6c64aa27089f9988bb37b..62d6a8cc4c4c8e75ed8a100f65f83bb22553c489 100644
--- a/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C
+++ b/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -339,16 +339,17 @@ void subsetTopoSets
 
         // Map the data
         bitSet isSet(set.maxSize(mesh));
-        forAllConstIter(labelHashSet, set, iter)
+        for (const label id : set)
         {
-            isSet.set(iter.key());
+            isSet.set(id);
         }
+
         label nSet = 0;
-        forAll(map, i)
+        for (const label id : map)
         {
-            if (isSet[map[i]])
+            if (isSet.test(id))
             {
-                nSet++;
+                ++nSet;
             }
         }
 
@@ -358,9 +359,10 @@ void subsetTopoSets
             new TopoSet(subMesh, set.name(), nSet, IOobject::AUTO_WRITE)
         );
         TopoSet& subSet = subSets[i];
+
         forAll(map, i)
         {
-            if (isSet[map[i]])
+            if (isSet.test(map[i]))
             {
                 subSet.insert(i);
             }
diff --git a/applications/utilities/mesh/advanced/combinePatchFaces/combinePatchFaces.C b/applications/utilities/mesh/advanced/combinePatchFaces/combinePatchFaces.C
index 3423d698654de6cde2881cec057435437745af5b..20db80ffa04ec3ea4ce959af5db89124e0400340 100644
--- a/applications/utilities/mesh/advanced/combinePatchFaces/combinePatchFaces.C
+++ b/applications/utilities/mesh/advanced/combinePatchFaces/combinePatchFaces.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -92,12 +92,12 @@ label mergePatchFaces
     {
         // Store the faces of the face sets
         List<faceList> allFaceSetsFaces(allFaceSets.size());
-        forAll(allFaceSets, setI)
+        forAll(allFaceSets, seti)
         {
-            allFaceSetsFaces[setI] = UIndirectList<face>
+            allFaceSetsFaces[seti] = UIndirectList<face>
             (
                 mesh.faces(),
-                allFaceSets[setI]
+                allFaceSets[seti]
             );
         }
 
@@ -146,13 +146,13 @@ label mergePatchFaces
         // Sets where the master is in error
         labelHashSet errorSets;
 
-        forAll(allFaceSets, setI)
+        forAll(allFaceSets, seti)
         {
-            label newMasterI = map().reverseFaceMap()[allFaceSets[setI][0]];
+            label newMasterI = map().reverseFaceMap()[allFaceSets[seti][0]];
 
             if (errorFaces.found(newMasterI))
             {
-                errorSets.insert(setI);
+                errorSets.insert(seti);
             }
         }
         label nErrorSets = returnReduce(errorSets.size(), sumOp<label>());
@@ -162,14 +162,12 @@ label mergePatchFaces
             << " These will be restored to their original faces."
             << endl;
 
-        if (nErrorSets > 0)
+        if (nErrorSets)
         {
             // Renumber stored faces to new vertex numbering.
-            forAllConstIter(labelHashSet, errorSets, iter)
+            for (const label seti : errorSets)
             {
-                label setI = iter.key();
-
-                faceList& setFaceVerts = allFaceSetsFaces[setI];
+                faceList& setFaceVerts = allFaceSetsFaces[seti];
 
                 forAll(setFaceVerts, i)
                 {
@@ -183,8 +181,8 @@ label mergePatchFaces
                         if (newVertI < 0)
                         {
                             FatalErrorInFunction
-                                << "In set:" << setI << " old face labels:"
-                                << allFaceSets[setI] << " new face vertices:"
+                                << "In set:" << seti << " old face labels:"
+                                << allFaceSets[seti] << " new face vertices:"
                                 << setFaceVerts[i] << " are unmapped vertices!"
                                 << abort(FatalError);
                         }
@@ -198,12 +196,10 @@ label mergePatchFaces
 
 
             // Restore faces
-            forAllConstIter(labelHashSet, errorSets, iter)
+            for (const label seti : errorSets)
             {
-                label setI = iter.key();
-
-                const labelList& setFaces = allFaceSets[setI];
-                const faceList& setFaceVerts = allFaceSetsFaces[setI];
+                const labelList& setFaces = allFaceSets[seti];
+                const faceList& setFaceVerts = allFaceSetsFaces[seti];
 
                 label newMasterI = map().reverseFaceMap()[setFaces[0]];
 
@@ -241,7 +237,7 @@ label mergePatchFaces
 
 
                 // Add the previously removed faces
-                for (label i = 1; i < setFaces.size(); i++)
+                for (label i = 1; i < setFaces.size(); ++i)
                 {
                     Pout<< "Restoring removed face " << setFaces[i]
                         << " with vertices " << setFaceVerts[i] << endl;
diff --git a/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C b/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C
index 3a1926dbdda1be7d9fa679c7513ddfc35e16c9f6..2f268c447ab3da10d60139782d198356af130ad6 100644
--- a/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C
+++ b/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -300,9 +300,8 @@ void addCutNeighbours
 
     labelHashSet addCutFaces(cutCells.size());
 
-    forAllConstIter(labelHashSet, cutCells, iter)
+    for (const label celli : cutCells)
     {
-        const label celli = iter.key();
         const labelList& cFaces = mesh.cells()[celli];
 
         forAll(cFaces, i)
@@ -333,9 +332,9 @@ void addCutNeighbours
     Info<< "    Selected an additional " << addCutFaces.size()
         << " neighbours of cutCells to refine" << endl;
 
-    forAllConstIter(labelHashSet, addCutFaces, iter)
+    for (const label facei : addCutFaces)
     {
-        cutCells.insert(iter.key());
+        cutCells.insert(facei);
     }
 }
 
@@ -383,10 +382,9 @@ bool limitRefinementLevel
 
     labelHashSet addCutCells(cutCells.size());
 
-    forAllConstIter(labelHashSet, cutCells, iter)
+    for (const label celli : cutCells)
     {
-        // cellI will be refined.
-        const label celli = iter.key();
+        // celli will be refined.
         const labelList& cCells = mesh.cellCells()[celli];
 
         forAll(cCells, i)
@@ -411,9 +409,9 @@ bool limitRefinementLevel
             << " to satisfy 1:" << limitDiff << " refinement level"
             << endl;
 
-        forAllConstIter(labelHashSet, addCutCells, iter)
+        for (const label celli : addCutCells)
         {
-            cutCells.insert(iter.key());
+            cutCells.insert(celli);
         }
         return true;
     }
diff --git a/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C b/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C
index 3e06227f01c61b72c607d288123df85fa87bc57a..8530d69541e765224beb9c9756feee7a796b4762 100644
--- a/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C
+++ b/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -360,9 +360,9 @@ void writePointCells
 
     label vertI = 0;
 
-    forAllConstIter(labelHashSet, allEdges, iter)
+    for (const label edgei : allEdges)
     {
-        const edge& e = mesh.edges()[iter.key()];
+        const edge& e = mesh.edges()[edgei];
 
         meshTools::writeOBJ(pointStream, mesh.points()[e[0]]); vertI++;
         meshTools::writeOBJ(pointStream, mesh.points()[e[1]]); vertI++;
diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C
index ea9d7602883bf204af7d5bd2b105f685fda6e161..7fcbfffd107d491a187ce85775b2e7c96de8bf95 100644
--- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C
+++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2012-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -886,10 +886,10 @@ void Foam::conformalVoronoiMesh::checkCellSizing()
         labelHashSet cellsToResizeMap(pMesh.nFaces()/100);
 
         // Find cells that are attached to the faces in wrongFaces.
-        forAllConstIter(labelHashSet, wrongFaces, iter)
+        for (const label facei : wrongFaces)
         {
-            const label faceOwner = pMesh.faceOwner()[iter.key()];
-            const label faceNeighbour = pMesh.faceNeighbour()[iter.key()];
+            const label faceOwner = pMesh.faceOwner()[facei];
+            const label faceNeighbour = pMesh.faceNeighbour()[facei];
 
             if (!cellsToResizeMap.found(faceOwner))
             {
@@ -1105,9 +1105,9 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
 
     bitSet ptToBeLimited(pts.size(), false);
 
-    forAllConstIter(labelHashSet, wrongFaces, iter)
+    for (const label facei : wrongFaces)
     {
-        const face f = pMesh.faces()[iter.key()];
+        const face f = pMesh.faces()[facei];
 
         ptToBeLimited.setMany(f);
     }
@@ -1118,9 +1118,9 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
 
     // const labelListList& ptCells = pMesh.pointCells();
 
-    // forAllConstIter(labelHashSet, wrongFaces, iter)
+    // for (const label facei : wrongFaces)
     // {
-    //     const face f = pMesh.faces()[iter.key()];
+    //     const face f = pMesh.faces()[facei];
 
     //     forAll(f, fPtI)
     //     {
@@ -1132,10 +1132,8 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
 
     // const labelListList& cellPts = pMesh.cellPoints();
 
-    // forAllConstIter(labelHashSet, limitCells, iter)
+    // for (const label celli : limitCells)
     // {
-    //     label celli = iter.key();
-
     //     const labelList& cP = cellPts[celli];
 
     //     ptToBeLimited.setMany(cP);
diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C
index be0325d8d2652c83092829e5552fb3d4b250acfb..c5ebc807cc5de3fa0fc17ea7674bf9c7254383e4 100644
--- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C
+++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -394,9 +394,9 @@ void extractSurface
     //  processor patches)
     HashTable<label> patchSize(1024);
     label nFaces = 0;
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchi : includePatches)
     {
-        const polyPatch& pp = bMesh[iter.key()];
+        const polyPatch& pp = bMesh[patchi];
         patchSize.insert(pp.name(), pp.size());
         nFaces += pp.size();
     }
@@ -427,9 +427,9 @@ void extractSurface
     // Collect faces on zones
     DynamicList<label> faceLabels(nFaces);
     DynamicList<label> compactZones(nFaces);
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchi : includePatches)
     {
-        const polyPatch& pp = bMesh[iter.key()];
+        const polyPatch& pp = bMesh[patchi];
         forAll(pp, i)
         {
             faceLabels.append(pp.start()+i);
diff --git a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C
index 890f541dd1ddab5551392c4b8a3d5e3bec1ac409..784ee755a567d77add11fa3245345c6078de0918 100644
--- a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C
+++ b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -837,9 +837,9 @@ int main(int argc, char *argv[])
         fvMeshMapper mapper(mesh, map());
         bool hasWarned = false;
 
-        forAllConstIter(wordHashSet, bafflePatches, iter)
+        for (const word& patchName : bafflePatches)
         {
-            label patchi = mesh.boundaryMesh().findPatchID(iter.key());
+            label patchi = mesh.boundaryMesh().findPatchID(patchName);
 
             const fvPatchMapper& pm = mapper.boundaryMap()[patchi];
 
diff --git a/applications/utilities/mesh/manipulation/createPatch/createPatch.C b/applications/utilities/mesh/manipulation/createPatch/createPatch.C
index ecb3ec4aedc401af474832b6e5d790791204e89d..795a61f76ef6460ddc6163745cf87cce6df79f67 100644
--- a/applications/utilities/mesh/manipulation/createPatch/createPatch.C
+++ b/applications/utilities/mesh/manipulation/createPatch/createPatch.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -699,9 +699,9 @@ int main(int argc, char *argv[])
             );
 
             // Repatch faces of the patches.
-            forAllConstIter(labelHashSet, patchSources, iter)
+            for (const label patchi : patchSources)
             {
-                const polyPatch& pp = patches[iter.key()];
+                const polyPatch& pp = patches[patchi];
 
                 Info<< "Moving faces from patch " << pp.name()
                     << " to patch " << destPatchi << endl;
diff --git a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C
index 1b9c88217dbf6efea31fe37d3607a87c4c2d092c..927704a5ed736b17ded745ddd3be2565aaf453f9 100644
--- a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C
+++ b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -1131,9 +1131,8 @@ int main(int argc, char *argv[])
 
             // Detect any flips.
             const labelHashSet& fff = map().flipFaceFlux();
-            forAllConstIter(labelHashSet, fff, iter)
+            for (const label facei : fff)
             {
-                label facei = iter.key();
                 label masterFacei = faceProcAddressing[facei];
 
                 faceProcAddressing[facei] = -masterFacei;
diff --git a/applications/utilities/mesh/manipulation/splitMesh/regionSide.C b/applications/utilities/mesh/manipulation/splitMesh/regionSide.C
index f06cfe28ea5d295b8b78c64910c93418e926bcec..b3308984d03cc9aea0f40c415792441c1d3b716c 100644
--- a/applications/utilities/mesh/manipulation/splitMesh/regionSide.C
+++ b/applications/utilities/mesh/manipulation/splitMesh/regionSide.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -296,9 +296,8 @@ void Foam::regionSide::walkAllPointConnectedFaces
     //
     labelHashSet regionEdges(4*regionFaces.size());
 
-    forAllConstIter(labelHashSet, regionFaces, iter)
+    for (const label facei : regionFaces)
     {
-        const label facei = iter.key();
         const labelList& fEdges = mesh.faceEdges()[facei];
 
         regionEdges.insertMany(fEdges);
@@ -313,9 +312,9 @@ void Foam::regionSide::walkAllPointConnectedFaces
     labelHashSet visitedPoint(4*regionFaces.size());
 
     // Insert fence points so we don't visit them
-    forAllConstIter(labelHashSet, fencePoints, iter)
+    for (const label pointi : fencePoints)
     {
-        visitedPoint.insert(iter.key());
+        visitedPoint.insert(pointi);
     }
 
     labelHashSet visitedEdges(2*fencePoints.size());
@@ -326,10 +325,8 @@ void Foam::regionSide::walkAllPointConnectedFaces
         Info<< "Excluding visit of points:" << visitedPoint << endl;
     }
 
-    forAllConstIter(labelHashSet, regionFaces, iter)
+    for (const label facei : regionFaces)
     {
-        const label facei = iter.key();
-
         // Get side of face.
         label celli;
 
@@ -436,9 +433,9 @@ Foam::regionSide::regionSide
 
     labelHashSet fencePoints(fenceEdges.size());
 
-    forAllConstIter(labelHashSet, fenceEdges, iter)
+    for (const label edgei : fenceEdges)
     {
-        const edge& e = mesh.edges()[iter.key()];
+        const edge& e = mesh.edges()[edgei];
 
         fencePoints.insert(e.start());
         fencePoints.insert(e.end());
diff --git a/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C b/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C
index 59f869d1a0d3870a4d548481323c7dbfe57fa28b..82ae5dc48889ababcfe380cfcc7681b622fd7601 100644
--- a/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C
+++ b/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -90,9 +90,8 @@ triSurface triangulate
     label newPatchI = 0;
     label localTriFaceI = 0;
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchI : includePatches)
     {
-        const label patchI = iter.key();
         const polyPatch& patch = bMesh[patchI];
         const pointField& points = patch.points();
 
@@ -147,9 +146,8 @@ triSurface triangulate
 
     newPatchI = 0;
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchI : includePatches)
     {
-        const label patchI = iter.key();
         const polyPatch& patch = bMesh[patchI];
 
         surface.patches()[newPatchI].index() = patchI;
diff --git a/applications/utilities/surface/surfaceMeshTriangulate/surfaceMeshTriangulate.C b/applications/utilities/surface/surfaceMeshTriangulate/surfaceMeshTriangulate.C
index b5b2421b609ea16b9d0df746f86c1812d6b2f0e4..fe1f63ffb817397f56ef7531f9c3768b91e918e4 100644
--- a/applications/utilities/surface/surfaceMeshTriangulate/surfaceMeshTriangulate.C
+++ b/applications/utilities/surface/surfaceMeshTriangulate/surfaceMeshTriangulate.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2017-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -210,7 +210,6 @@ int main(int argc, char *argv[])
                         << "Cannot find any faceZone name matching "
                         << zoneName << endl;
                 }
-
             }
             Info<< "Additionally triangulating faceZones "
                 <<  UIndirectList<word>
@@ -234,17 +233,17 @@ int main(int argc, char *argv[])
             //  processor patches)
             HashTable<label> patchSize(1024);
             label nFaces = 0;
-            forAllConstIter(labelHashSet, includePatches, iter)
+            for (const label patchi : includePatches)
             {
-                const polyPatch& pp = bMesh[iter.key()];
+                const polyPatch& pp = bMesh[patchi];
                 patchSize.insert(pp.name(), pp.size());
                 nFaces += pp.size();
             }
 
             HashTable<label> zoneSize(1024);
-            forAllConstIter(labelHashSet, includeFaceZones, iter)
+            for (const label zonei : includeFaceZones)
             {
-                const faceZone& pp = fzm[iter.key()];
+                const faceZone& pp = fzm[zonei];
                 zoneSize.insert(pp.name(), pp.size());
                 nFaces += pp.size();
             }
@@ -295,9 +294,9 @@ int main(int argc, char *argv[])
             compactZones.setCapacity(nFaces);
 
             // Collect faces on patches
-            forAllConstIter(labelHashSet, includePatches, iter)
+            for (const label patchi : includePatches)
             {
-                const polyPatch& pp = bMesh[iter.key()];
+                const polyPatch& pp = bMesh[patchi];
                 forAll(pp, i)
                 {
                     faceLabels.append(pp.start()+i);
@@ -305,9 +304,9 @@ int main(int argc, char *argv[])
                 }
             }
             // Collect faces on faceZones
-            forAllConstIter(labelHashSet, includeFaceZones, iter)
+            for (const label zonei : includeFaceZones)
             {
-                const faceZone& pp = fzm[iter.key()];
+                const faceZone& pp = fzm[zonei];
                 forAll(pp, i)
                 {
                     faceLabels.append(pp[i]);
diff --git a/src/OpenFOAM/fields/ReadFields/ReadFields.C b/src/OpenFOAM/fields/ReadFields/ReadFields.C
index 1914e3f06b686a31aaff7910e90f8f5e5518d04d..df4afd2159d24d37edc080b90b76be14b19ca642 100644
--- a/src/OpenFOAM/fields/ReadFields/ReadFields.C
+++ b/src/OpenFOAM/fields/ReadFields/ReadFields.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -70,7 +70,7 @@ Foam::wordList Foam::fieldNames
             }
         }
 
-        forAllConstIter(wordHashSet, localNamesSet, iter)
+        if (localNamesSet.size())
         {
             FatalErrorInFunction
                 << "Fields not synchronised across processors." << endl
diff --git a/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C b/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C
index 38354fbd80e2a5bcbafc251290e2aa40ddacc576..d9c4960d485938f9f6bbd0c21821102c6df7e6d2 100644
--- a/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C
+++ b/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2014 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -408,7 +408,7 @@ void Foam::readUniformFields
             }
         }
 
-        forAllConstIter(wordHashSet, localNamesSet, iter)
+        if (localNamesSet.size())
         {
             FatalErrorInFunction
                 << "Fields not synchronised across processors." << endl
diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
index 3da0f018a0a1c5bb3d0fa54a5ba58cdd1cc0d8ca..93e007ad4a4ca56b07dd410a4e56872585c1577b 100644
--- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
+++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
@@ -312,10 +312,9 @@ void Foam::fileOperation::addWatches
     DynamicList<label> newWatchIndices;
     labelHashSet removedWatches(watchIndices);
 
-    forAll(files, i)
+    for (const fileName& f : files)
     {
-        const fileName& f = files[i];
-        label index = findWatch(watchIndices, f);
+        const label index = findWatch(watchIndices, f);
 
         if (index == -1)
         {
@@ -330,9 +329,9 @@ void Foam::fileOperation::addWatches
     }
 
     // Remove any unused watches
-    forAllConstIter(labelHashSet, removedWatches, iter)
+    for (const label index : removedWatches)
     {
-        removeWatch(watchIndices[iter.key()]);
+        removeWatch(watchIndices[index]);
     }
 
     rio.watchIndices() = newWatchIndices;
diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
index cc6fbe6eaa49b4828f2641aeb1da30cd6758c336..4d97c0bdad6109b2b339d39250990c1f16499162 100644
--- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
+++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
@@ -1732,10 +1732,9 @@ void Foam::fileOperations::masterUncollatedFileOperation::addWatches
     DynamicList<label> newWatchIndices;
     labelHashSet removedWatches(watchIndices);
 
-    forAll(files, i)
+    for (const fileName& f : files)
     {
-        const fileName& f = files[i];
-        label index = findWatch(watchIndices, f);
+        const label index = findWatch(watchIndices, f);
 
         if (index == -1)
         {
@@ -1750,9 +1749,9 @@ void Foam::fileOperations::masterUncollatedFileOperation::addWatches
     }
 
     // Remove any unused watches
-    forAllConstIter(labelHashSet, removedWatches, iter)
+    for (const label index : removedWatches)
     {
-        removeWatch(watchIndices[iter.key()]);
+        removeWatch(watchIndices[index]);
     }
 
     rio.watchIndices() = newWatchIndices;
diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C
index ab96883fbfde4332eddf4d70381e259cfadc2ad5..6f08ea4471eb3e390ae822a1331d28689a395077 100644
--- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C
+++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -66,31 +66,29 @@ const Foam::labelList& Foam::primitiveMesh::cellPoints
     {
         return cellPoints()[celli];
     }
-    else
-    {
-        const faceList& fcs = faces();
-        const labelList& cFaces = cells()[celli];
 
-        set.clear();
+    const faceList& fcs = faces();
+    const labelList& cFaces = cells()[celli];
 
-        for (const label facei : cFaces)
-        {
-            set.insertMany(fcs[facei]);
-        }
+    set.clear();
 
-        storage.clear();
-        if (set.size() > storage.capacity())
-        {
-            storage.setCapacity(set.size());
-        }
+    for (const label facei : cFaces)
+    {
+        set.insertMany(fcs[facei]);
+    }
 
-        for (const label pointi : set)
-        {
-            storage.append(pointi);
-        }
+    storage.clear();
+    if (set.size() > storage.capacity())
+    {
+        storage.setCapacity(set.size());
+    }
 
-        return storage;
+    for (const label pointi : set)
+    {
+        storage.append(pointi);
     }
+
+    return storage;
 }
 
 
diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C
index d11d83deb49717bec9f9c0d2756993e44663b2af..8f0d07e3120dbd658ccc32cda19f0872bc6aa38f 100644
--- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C
+++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -593,31 +593,29 @@ const Foam::labelList& Foam::primitiveMesh::faceEdges
     {
         return faceEdges()[facei];
     }
-    else
-    {
-        const labelListList& pointEs = pointEdges();
-        const face& f = faces()[facei];
 
-        storage.clear();
-        if (f.size() > storage.capacity())
-        {
-            storage.setCapacity(f.size());
-        }
+    const labelListList& pointEs = pointEdges();
+    const face& f = faces()[facei];
 
-        forAll(f, fp)
-        {
-            storage.append
-            (
-                findFirstCommonElementFromSortedLists
-                (
-                    pointEs[f[fp]],
-                    pointEs[f.nextLabel(fp)]
-                )
-            );
-        }
+    storage.clear();
+    if (f.size() > storage.capacity())
+    {
+        storage.setCapacity(f.size());
+    }
 
-        return storage;
+    forAll(f, fp)
+    {
+        storage.append
+        (
+            findFirstCommonElementFromSortedLists
+            (
+                pointEs[f[fp]],
+                pointEs[f.nextLabel(fp)]
+            )
+        );
     }
+
+    return storage;
 }
 
 
@@ -638,30 +636,28 @@ const Foam::labelList& Foam::primitiveMesh::cellEdges
     {
         return cellEdges()[celli];
     }
-    else
-    {
-        const labelList& cFaces = cells()[celli];
 
-        set.clear();
+    const labelList& cFaces = cells()[celli];
 
-        for (const label facei : cFaces)
-        {
-            set.insertMany(faceEdges(facei));
-        }
+    set.clear();
 
-        storage.clear();
-        if (set.size() > storage.capacity())
-        {
-            storage.setCapacity(set.size());
-        }
+    for (const label facei : cFaces)
+    {
+        set.insertMany(faceEdges(facei));
+    }
 
-        for (const label edgei : set)
-        {
-            storage.append(edgei);
-        }
+    storage.clear();
+    if (set.size() > storage.capacity())
+    {
+        storage.setCapacity(set.size());
+    }
 
-        return storage;
+    for (const label edgei : set)
+    {
+        storage.append(edgei);
     }
+
+    return storage;
 }
 
 
diff --git a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H
index 56e74f2c7ddcd572ebdbe3020af43795d56be503..f47f7dffdc947626f84dd81a79d2c4b63ddf28f1 100644
--- a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H
+++ b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -424,10 +424,8 @@ Foam::labelList Foam::globalIndexAndTransform::transformIndicesForPatches
         return selectedTransformIs;
     }
 
-    forAllConstIter(labelHashSet, patchis, iter)
+    for (const label patchi : patchis)
     {
-        label patchi = iter.key();
-
         const labelPair& transSign = patchTransformSign_[patchi];
 
         label matchTransI = transSign.first();
diff --git a/src/conversion/fire/checkFireEdges.C b/src/conversion/fire/checkFireEdges.C
index ae2f1b6c96a795743a5f05f268ff0e0a32a17a13..e7a92d980d8c9b02d2140e105eb396010fa83e97 100644
--- a/src/conversion/fire/checkFireEdges.C
+++ b/src/conversion/fire/checkFireEdges.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -183,10 +183,8 @@ Foam::label Foam::checkFireEdges
             << "edge points" << nl
             << "~~~~~~~~~~~" << endl;
 
-
-        forAllConstIter(edgeHashSet, failedEdges, citer)
+        for (edge thisEdge : failedEdges)  // Use copy of edge
         {
-            edge thisEdge = citer.key();
             if (thisEdge.start() > thisEdge.end())
             {
                 thisEdge.flip();
@@ -262,9 +260,8 @@ Foam::label Foam::checkFireEdges
     else
     {
         // get the max point addressed
-        forAll(faces, faceI)
+        for (const face& f : faces)
         {
-            const face& f = faces[faceI];
             forAll(f, fp)
             {
                 if (nPoints < f[fp])
diff --git a/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C b/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C
index 699df4733bb7e1ca220c802ffde595c6a000751c..982cf21b536c80ffc735f955120a07c9e004e4c0 100644
--- a/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C
+++ b/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -395,10 +395,8 @@ Foam::dynamicRefineFvMesh::refine
             }
 
             // Update master faces
-            forAllConstIter(labelHashSet, masterFaces, iter)
+            for (const label facei : masterFaces)
             {
-                label facei = iter.key();
-
                 if (isInternalFace(facei))
                 {
                     phi[facei] = phiU[facei];
diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C
index cf502e92addbf689c478aa2dc5f2218dd3c56e12..4206ca325b54de63034dd01e268e0de48fb17289 100644
--- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C
+++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -2102,10 +2102,9 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
             faceMap[faceI] += 1;
         }
         const labelHashSet& flip = subMap().flipFaceFlux();
-        forAllConstIter(labelHashSet, flip, iter)
+        for (const label facei : flip)
         {
-            label faceI = iter.key();
-            faceMap[faceI] = -faceMap[faceI];
+            faceMap[facei] = -faceMap[facei];
         }
         subPointMap[Pstream::myProcNo()] = subMap().pointMap();
         subPatchMap[Pstream::myProcNo()] = identity(patches.size());
@@ -2567,9 +2566,8 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
             // Added processor
             inplaceRenumber(map().addedCellMap(), constructCellMap[sendProc]);
             // Add flip
-            forAllConstIter(labelHashSet, flippedAddedFaces, iter)
+            for (const label domainFaceI : flippedAddedFaces)
             {
-                label domainFaceI = iter.key();
                 label& val = constructFaceMap[sendProc][domainFaceI];
                 val = -val;
             }
diff --git a/src/dynamicMesh/layerAdditionRemoval/removeCellLayer.C b/src/dynamicMesh/layerAdditionRemoval/removeCellLayer.C
index 4951c8f85a91c884b9448e8ba5570e86163c9473..7617a2ab9d0c20f5de58aefa791480009a0a2087 100644
--- a/src/dynamicMesh/layerAdditionRemoval/removeCellLayer.C
+++ b/src/dynamicMesh/layerAdditionRemoval/removeCellLayer.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -153,9 +153,9 @@ void Foam::layerAdditionRemoval::removeCellLayer
         }
     }
 
-    forAllConstIter(labelHashSet, facesToRemoveMap, iter)
+    for (const label facei : facesToRemoveMap)
     {
-        ref.setAction(polyRemoveFace(iter.key()));
+        ref.setAction(polyRemoveFace(facei));
     }
 
     // Remove all points that will be collapsed
diff --git a/src/dynamicMesh/meshCut/edgeVertex/edgeVertex.C b/src/dynamicMesh/meshCut/edgeVertex/edgeVertex.C
index 83b6a0b12763727b621ff3c649ec9b951b071d3a..6be1a6df1df66ed1b0e0a9e38d970c2b7cf31975 100644
--- a/src/dynamicMesh/meshCut/edgeVertex/edgeVertex.C
+++ b/src/dynamicMesh/meshCut/edgeVertex/edgeVertex.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -30,7 +30,6 @@ License
 
 // * * * * * * * * * * * * * * * Static Functions  * * * * * * * * * * * * * //
 
-
 // Update stored refine list using map
 void Foam::edgeVertex::updateLabels
 (
@@ -131,11 +130,11 @@ void Foam::edgeVertex::updateLabels
     // Iterate over map to see if anything changed
     bool changed = false;
 
-    forAllConstIter(labelHashSet, cells, iter)
+    for (const label celli : cells)
     {
-        const label newCelli = map[iter.key()];
+        const label newCelli = map[celli];
 
-        if (newCelli != iter.key())
+        if (newCelli != celli)
         {
             changed = true;
 
@@ -148,9 +147,9 @@ void Foam::edgeVertex::updateLabels
     {
         labelHashSet newCells(2*cells.size());
 
-        forAllConstIter(labelHashSet, cells, iter)
+        for (const label celli : cells)
         {
-            const label newCelli = map[iter.key()];
+            const label newCelli = map[celli];
 
             if (newCelli != -1)
             {
diff --git a/src/dynamicMesh/motionSmoother/motionSmootherAlgo.C b/src/dynamicMesh/motionSmoother/motionSmootherAlgo.C
index 61032b10c1d382302a7de4e713a3f72646e58e49..bfc9eb1f5836632d1084fcf045a721ae3f2ea1eb 100644
--- a/src/dynamicMesh/motionSmoother/motionSmootherAlgo.C
+++ b/src/dynamicMesh/motionSmoother/motionSmootherAlgo.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -257,11 +257,11 @@ void Foam::motionSmootherAlgo::subtractField
     pointScalarField& fld
 ) const
 {
-    forAllConstIter(labelHashSet, pointLabels, iter)
+    for (const label pointi : pointLabels)
     {
-        if (isInternalPoint(iter.key()))
+        if (isInternalPoint(pointi))
         {
-            fld[iter.key()] = max(0.0, fld[iter.key()]-f);
+            fld[pointi] = max(0.0, fld[pointi]-f);
         }
     }
 
@@ -306,7 +306,7 @@ void Foam::motionSmootherAlgo::getAffectedFacesAndPoints
     bitSet& isAffectedPoint
 ) const
 {
-    isAffectedPoint.setSize(mesh_.nPoints());
+    isAffectedPoint.resize(mesh_.nPoints());
     isAffectedPoint = false;
 
     faceSet nbrFaces(mesh_, "checkFaces", wrongFaces);
@@ -320,9 +320,9 @@ void Foam::motionSmootherAlgo::getAffectedFacesAndPoints
     {
         pointSet nbrPoints(mesh_, "grownPoints", getPoints(nbrFaces.toc()));
 
-        forAllConstIter(pointSet, nbrPoints, iter)
+        for (const label pointi : nbrPoints)
         {
-            const labelList& pCells = mesh_.pointCells(iter.key());
+            const labelList& pCells = mesh_.pointCells(pointi);
 
             forAll(pCells, pCelli)
             {
@@ -335,9 +335,9 @@ void Foam::motionSmootherAlgo::getAffectedFacesAndPoints
 
         if (i == nPointIter - 2)
         {
-            forAllConstIter(faceSet, nbrFaces, iter)
+            for (const label facei : nbrFaces)
             {
-                const face& f = mesh_.faces()[iter.key()];
+                const face& f = mesh_.faces()[facei];
                 isAffectedPoint.setMany(f);
             }
         }
@@ -939,16 +939,16 @@ bool Foam::motionSmootherAlgo::scaleMesh
         if (mag(errorReduction) < SMALL)
         {
             labelHashSet newWrongFaces(wrongFaces);
-            forAllConstIter(labelHashSet, wrongFaces, iter)
+            for (const label facei : wrongFaces)
             {
-                label own = mesh_.faceOwner()[iter.key()];
+                const label own = mesh_.faceOwner()[facei];
                 const cell& ownFaces = mesh_.cells()[own];
 
                 newWrongFaces.insertMany(ownFaces);
 
-                if (iter.key() < mesh_.nInternalFaces())
+                if (facei < mesh_.nInternalFaces())
                 {
-                    label nei = mesh_.faceNeighbour()[iter.key()];
+                    const label nei = mesh_.faceNeighbour()[facei];
                     const cell& neiFaces = mesh_.cells()[nei];
 
                     newWrongFaces.insertMany(neiFaces);
diff --git a/src/dynamicMesh/perfectInterface/perfectInterface.C b/src/dynamicMesh/perfectInterface/perfectInterface.C
index 81cf5fb4a62ffc47a9d5b1178536383abf66e323..6d7960e13e7e9ab7f8de892f6d0fcd19dbebb4f7 100644
--- a/src/dynamicMesh/perfectInterface/perfectInterface.C
+++ b/src/dynamicMesh/perfectInterface/perfectInterface.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -288,9 +288,8 @@ void Foam::perfectInterface::setRefinement
 
 
     // 2. Renumber (non patch0/1) faces.
-    forAllConstIter(labelHashSet, affectedFaces, iter)
+    for (const label facei : affectedFaces)
     {
-        const label facei = iter.key();
         const face& f = mesh.faces()[facei];
 
         face newFace(f.size());
diff --git a/src/dynamicMesh/pointPatchDist/pointPatchDist.C b/src/dynamicMesh/pointPatchDist/pointPatchDist.C
index ad86b0c4396863c055b685fb4f9f2082cb0600a0..bc194bbb89465f4cd302b8d9c6a142690d8a1a49 100644
--- a/src/dynamicMesh/pointPatchDist/pointPatchDist.C
+++ b/src/dynamicMesh/pointPatchDist/pointPatchDist.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2013-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -70,9 +70,8 @@ void Foam::pointPatchDist::correct()
 
     label nPoints = 0;
 
-    forAllConstIter(labelHashSet, patchIDs_, iter)
+    for (const label patchi : patchIDs_)
     {
-        label patchi = iter.key();
         nPoints += pbm[patchi].meshPoints().size();
     }
 
@@ -83,9 +82,8 @@ void Foam::pointPatchDist::correct()
     labelList wallPoints(nPoints);
     nPoints = 0;
 
-    forAllConstIter(labelHashSet, patchIDs_, iter)
+    for (const label patchi : patchIDs_)
     {
-        label patchi = iter.key();
         // Retrieve the patch now we have its index in patches.
 
         const labelList& mp = pbm[patchi].meshPoints();
diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C
index 6499498e3e2438289ac3e88781b302d5a6c99144..426866008b5094dd8e70de8ae1b7feae598c1669 100644
--- a/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C
+++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -309,10 +309,8 @@ Foam::labelListList Foam::combineFaces::getMergeSets
     DynamicList<label> storage;
 
     // On all cells regionise the faces
-    forAllConstIter(labelHashSet, boundaryCells, iter)
+    for (const label celli : boundaryCells)
     {
-        label celli = iter.key();
-
         const cell& cFaces = mesh_.cells()[celli];
 
         const labelList& cEdges = mesh_.cellEdges(celli, set, storage);
diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/faceCollapser.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/faceCollapser.C
index 3b6ad1fa087f16a66fc2513ff58d24cc86a89295..3518ed8bbcde21f356b1fefa7fe47ea4de7d31ab 100644
--- a/src/dynamicMesh/polyTopoChange/polyTopoChange/faceCollapser.C
+++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/faceCollapser.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -495,9 +495,9 @@ void Foam::faceCollapser::setRefinement
     // Modify faces affected (but not removed)
     //
 
-    forAllConstIter(labelHashSet, affectedFaces, iter)
+    for (const label facei : affectedFaces)
     {
-        filterFace(splitEdges, iter.key(), meshMod);
+        filterFace(splitEdges, facei, meshMod);
     }
 }
 
diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/removeFaces.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/removeFaces.C
index 720c109d90c1a193e5b3661c55e39ac0bee06898..031ee932d0b18822d736ab19149ca6e63ace66d3 100644
--- a/src/dynamicMesh/polyTopoChange/polyTopoChange/removeFaces.C
+++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/removeFaces.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -170,9 +170,9 @@ Foam::boolList Foam::removeFaces::getFacesAffected
     }
 
     //  Mark faces affected by removal of edges
-    forAllConstIter(labelHashSet, edgesToRemove, iter)
+    for (const label edgei : edgesToRemove)
     {
-        const labelList& eFaces = mesh_.edgeFaces(iter.key());
+        const labelList& eFaces = mesh_.edgeFaces(edgei);
 
         forAll(eFaces, eFacei)
         {
@@ -181,10 +181,8 @@ Foam::boolList Foam::removeFaces::getFacesAffected
     }
 
     // Mark faces affected by removal of points
-    forAllConstIter(labelHashSet, pointsToRemove, iter)
+    for (const label pointi : pointsToRemove)
     {
-        label pointi = iter.key();
-
         const labelList& pFaces = mesh_.pointFaces()[pointi];
 
         forAll(pFaces, pFacei)
@@ -1100,10 +1098,10 @@ void Foam::removeFaces::setRefinement
             Pout<< "Dumping edgesToRemove to " << str.name() << endl;
             label vertI = 0;
 
-            forAllConstIter(labelHashSet, edgesToRemove, iter)
+            for (const label edgei : edgesToRemove)
             {
                 // Edge will get removed.
-                const edge& e = mesh_.edges()[iter.key()];
+                const edge& e = mesh_.edges()[edgei];
 
                 meshTools::writeOBJ(str, mesh_.points()[e[0]]);
                 vertI++;
@@ -1260,10 +1258,10 @@ void Foam::removeFaces::setRefinement
             nEdgesPerPoint[pointi] = pointEdges[pointi].size();
         }
 
-        forAllConstIter(labelHashSet, edgesToRemove, iter)
+        for (const label edgei : edgesToRemove)
         {
             // Edge will get removed.
-            const edge& e = mesh_.edges()[iter.key()];
+            const edge& e = mesh_.edges()[edgei];
 
             forAll(e, i)
             {
@@ -1318,9 +1316,9 @@ void Foam::removeFaces::setRefinement
         OFstream str(mesh_.time().path()/"pointsToRemove.obj");
         Pout<< "Dumping pointsToRemove to " << str.name() << endl;
 
-        forAllConstIter(labelHashSet, pointsToRemove, iter)
+        for (const label pointi : pointsToRemove)
         {
-            meshTools::writeOBJ(str, mesh_.points()[iter.key()]);
+            meshTools::writeOBJ(str, mesh_.points()[pointi]);
         }
     }
 
@@ -1374,10 +1372,8 @@ void Foam::removeFaces::setRefinement
 
 
     // Remove points.
-    forAllConstIter(labelHashSet, pointsToRemove, iter)
+    for (const label pointi : pointsToRemove)
     {
-        label pointi = iter.key();
-
         meshMod.setAction(polyRemovePoint(pointi, -1));
     }
 
diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C
index 7b6b04cc6b095acfed12dbfa1a7c88bb67a77362..594f2e279efa070a6eab973d13a305acfdca3c8e 100644
--- a/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C
+++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -360,10 +360,8 @@ void Foam::removePoints::setRefinement
     }
     label nSaved = 0;
 
-    forAllConstIter(labelHashSet, facesAffected, iter)
+    for (const label facei : facesAffected)
     {
-        label facei = iter.key();
-
         const face& f = mesh_.faces()[facei];
 
         face newFace(f.size());
diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C
index cf6fafb3d96cbe3907fd4f6886a8e690f9792a91..7cf9160ce1ad14f030e274967bb6dee5daa16cb5 100644
--- a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C
+++ b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -278,9 +278,9 @@ Foam::MRFZone::MRFZone
         excludedPatchLabels_.setSize(excludedPatchSet.size());
 
         label i = 0;
-        forAllConstIter(labelHashSet, excludedPatchSet, iter)
+        for (const label patchi : excludedPatchSet)
         {
-            excludedPatchLabels_[i++] = iter.key();
+            excludedPatchLabels_[i++] = patchi;
         }
 
         bool cellZoneFound = (cellZoneID_ != -1);
diff --git a/src/finiteVolume/fvMesh/extendedStencil/cellToCell/globalIndexStencils/cellToCellStencil.C b/src/finiteVolume/fvMesh/extendedStencil/cellToCell/globalIndexStencils/cellToCellStencil.C
index cec896d7e36ad853af26a96c89457d7cf2e0fe88..b2ecb94b9593e739430452e244b5e389f705fa00 100644
--- a/src/finiteVolume/fvMesh/extendedStencil/cellToCell/globalIndexStencils/cellToCellStencil.C
+++ b/src/finiteVolume/fvMesh/extendedStencil/cellToCell/globalIndexStencils/cellToCellStencil.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -138,19 +138,19 @@ void Foam::cellToCellStencil::merge
 )
 {
     labelHashSet set;
-    forAll(cCells, i)
+    for (const label celli : cCells)
     {
-        if (cCells[i] != globalI)
+        if (celli != globalI)
         {
-            set.insert(cCells[i]);
+            set.insert(celli);
         }
     }
 
-    forAll(pGlobals, i)
+    for (const label celli : pGlobals)
     {
-        if (pGlobals[i] != globalI)
+        if (celli != globalI)
         {
-            set.insert(pGlobals[i]);
+            set.insert(celli);
         }
     }
 
@@ -158,9 +158,9 @@ void Foam::cellToCellStencil::merge
     label n = 0;
     cCells[n++] = globalI;
 
-    forAllConstIter(labelHashSet, set, iter)
+    for (const label seti : set)
     {
-        cCells[n++] = iter.key();
+        cCells[n++] = seti;
     }
 }
 
@@ -171,10 +171,8 @@ void Foam::cellToCellStencil::validBoundaryFaces(boolList& isValidBFace) const
 
     isValidBFace.setSize(mesh().nFaces()-mesh().nInternalFaces(), true);
 
-    forAll(patches, patchi)
+    for (const polyPatch& pp : patches)
     {
-        const polyPatch& pp = patches[patchi];
-
         if (pp.coupled() || isA<emptyPolyPatch>(pp))
         {
             label bFacei = pp.start()-mesh().nInternalFaces();
@@ -194,10 +192,8 @@ Foam::cellToCellStencil::allCoupledFacesPatch() const
 
     label nCoupled = 0;
 
-    forAll(patches, patchi)
+    for (const polyPatch& pp : patches)
     {
-        const polyPatch& pp = patches[patchi];
-
         if (pp.coupled())
         {
             nCoupled += pp.size();
@@ -206,10 +202,8 @@ Foam::cellToCellStencil::allCoupledFacesPatch() const
     labelList coupledFaces(nCoupled);
     nCoupled = 0;
 
-    forAll(patches, patchi)
+    for (const polyPatch& pp : patches)
     {
-        const polyPatch& pp = patches[patchi];
-
         if (pp.coupled())
         {
             label facei = pp.start();
diff --git a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/extendedUpwindCellToFaceStencil.C b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/extendedUpwindCellToFaceStencil.C
index be351280b975ebc5e53e61c4489439c065466a74..edd4da2e1e03e7a576e3229f495430dc431d02fc 100644
--- a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/extendedUpwindCellToFaceStencil.C
+++ b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/extendedUpwindCellToFaceStencil.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -159,11 +159,11 @@ void Foam::extendedUpwindCellToFaceStencil::transportStencil
         transportedStencil[n++] = globalOwn;
         transportedStencil[n++] = globalNei;
 
-        forAllConstIter(labelHashSet, faceStencilSet, iter)
+        for (const label stencili : faceStencilSet)
         {
-            if (iter.key() != globalOwn && iter.key() != globalNei)
+            if (stencili != globalOwn && stencili != globalNei)
             {
-                transportedStencil[n++] = iter.key();
+                transportedStencil[n++] = stencili;
             }
         }
         if (n != transportedStencil.size())
@@ -179,11 +179,11 @@ void Foam::extendedUpwindCellToFaceStencil::transportStencil
         label n = 0;
         transportedStencil[n++] = globalOwn;
 
-        forAllConstIter(labelHashSet, faceStencilSet, iter)
+        for (const label stencili : faceStencilSet)
         {
-            if (iter.key() != globalOwn)
+            if (stencili != globalOwn)
             {
-                transportedStencil[n++] = iter.key();
+                transportedStencil[n++] = stencili;
             }
         }
         if (n != transportedStencil.size())
diff --git a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/FECCellToFaceStencil.C b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/FECCellToFaceStencil.C
index f4e6eb88c93c86cac5274ea07665e24d38191171..801248524436257c976851de8c315c0ff52539e7 100644
--- a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/FECCellToFaceStencil.C
+++ b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/FECCellToFaceStencil.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -41,10 +41,8 @@ void Foam::FECCellToFaceStencil::calcEdgeBoundaryData
 
     labelHashSet edgeGlobals;
 
-    forAll(boundaryEdges, i)
+    for (const label edgeI : boundaryEdges)
     {
-        label edgeI = boundaryEdges[i];
-
         neiGlobal.insert
         (
             mesh().edges()[edgeI],
@@ -204,15 +202,15 @@ void Foam::FECCellToFaceStencil::calcFaceStencil
         label n = 0;
         faceStencil[facei][n++] = globalOwn;
         faceStencil[facei][n++] = globalNei;
-        forAllConstIter(labelHashSet, faceStencilSet, iter)
+        for (const label stencili : faceStencilSet)
         {
-            if (iter.key() == globalOwn || iter.key() == globalNei)
+            if (stencili == globalOwn || stencili == globalNei)
             {
                 FatalErrorInFunction
                     << "problem:" << faceStencilSet
                     << abort(FatalError);
             }
-            faceStencil[facei][n++] = iter.key();
+            faceStencil[facei][n++] = stencili;
         }
     }
     forAll(patches, patchi)
@@ -265,15 +263,15 @@ void Foam::FECCellToFaceStencil::calcFaceStencil
                 label n = 0;
                 faceStencil[facei][n++] = globalOwn;
                 faceStencil[facei][n++] = globalNei;
-                forAllConstIter(labelHashSet, faceStencilSet, iter)
+                for (const label stencili : faceStencilSet)
                 {
-                    if (iter.key() == globalOwn || iter.key() == globalNei)
+                    if (stencili == globalOwn || stencili == globalNei)
                     {
                         FatalErrorInFunction
                             << "problem:" << faceStencilSet
                             << abort(FatalError);
                     }
-                    faceStencil[facei][n++] = iter.key();
+                    faceStencil[facei][n++] = stencili;
                 }
 
                 if (n != faceStencil[facei].size())
@@ -329,15 +327,15 @@ void Foam::FECCellToFaceStencil::calcFaceStencil
                 faceStencil[facei].setSize(faceStencilSet.size()+1);
                 label n = 0;
                 faceStencil[facei][n++] = globalOwn;
-                forAllConstIter(labelHashSet, faceStencilSet, iter)
+                for (const label stencili : faceStencilSet)
                 {
-                    if (iter.key() == globalOwn)
+                    if (stencili == globalOwn)
                     {
                         FatalErrorInFunction
                             << "problem:" << faceStencilSet
                             << abort(FatalError);
                     }
-                    faceStencil[facei][n++] = iter.key();
+                    faceStencil[facei][n++] = stencili;
                 }
 
                 facei++;
diff --git a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/cellToFaceStencil.C b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/cellToFaceStencil.C
index 2a78462fa2f5e1dd795a4301c0add66dc206b77b..96318c05e9882f9b8114c5cec67ffb68ed56747c 100644
--- a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/cellToFaceStencil.C
+++ b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/cellToFaceStencil.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -66,10 +66,8 @@ void Foam::cellToFaceStencil::merge
     // For all in listA see if they are present
     label nInsert = 0;
 
-    forAll(listA, i)
+    for (const label elem : listA)
     {
-        label elem = listA[i];
-
         if (elem != global0 && elem != global1)
         {
             if (findSortedIndex(listB, elem) == -1)
@@ -96,10 +94,8 @@ void Foam::cellToFaceStencil::merge
 
 
     // Insert listB
-    forAll(listB, i)
+    for (const label elem : listB)
     {
-        label elem = listB[i];
-
         if (elem != global0 && elem != global1)
         {
             result[resultI++] = elem;
@@ -108,10 +104,8 @@ void Foam::cellToFaceStencil::merge
 
 
     // Insert listA
-    forAll(listA, i)
+    for (const label elem : listA)
     {
-        label elem = listA[i];
-
         if (elem != global0 && elem != global1)
         {
             if (findSortedIndex(listB, elem) == -1)
@@ -159,9 +153,9 @@ void Foam::cellToFaceStencil::merge
     label n = 0;
     cCells[n++] = globalI;
 
-    forAllConstIter(labelHashSet, set, iter)
+    for (const label seti : set)
     {
-        cCells[n++] = iter.key();
+        cCells[n++] = seti;
     }
 }
 
@@ -399,11 +393,11 @@ void Foam::cellToFaceStencil::calcFaceStencil
         label n = 0;
         faceStencil[facei][n++] = globalOwn;
         faceStencil[facei][n++] = globalNei;
-        forAllConstIter(labelHashSet, faceStencilSet, iter)
+        for (const label stencili : faceStencilSet)
         {
-            if (iter.key() != globalOwn && iter.key() != globalNei)
+            if (stencili != globalOwn && stencili != globalNei)
             {
-                faceStencil[facei][n++] = iter.key();
+                faceStencil[facei][n++] = stencili;
             }
         }
         //Pout<< "internalface:" << facei << " toc:" << faceStencilSet.toc()
@@ -435,11 +429,11 @@ void Foam::cellToFaceStencil::calcFaceStencil
                 label n = 0;
                 faceStencil[facei][n++] = globalOwn;
                 faceStencil[facei][n++] = globalNei;
-                forAllConstIter(labelHashSet, faceStencilSet, iter)
+                for (const label stencili : faceStencilSet)
                 {
-                    if (iter.key() != globalOwn && iter.key() != globalNei)
+                    if (stencili != globalOwn && stencili != globalNei)
                     {
-                        faceStencil[facei][n++] = iter.key();
+                        faceStencil[facei][n++] = stencili;
                     }
                 }
 
@@ -464,11 +458,11 @@ void Foam::cellToFaceStencil::calcFaceStencil
                 faceStencil[facei].setSize(faceStencilSet.size());
                 label n = 0;
                 faceStencil[facei][n++] = globalOwn;
-                forAllConstIter(labelHashSet, faceStencilSet, iter)
+                for (const label stencili : faceStencilSet)
                 {
-                    if (iter.key() != globalOwn)
+                    if (stencili != globalOwn)
                     {
-                        faceStencil[facei][n++] = iter.key();
+                        faceStencil[facei][n++] = stencili;
                     }
                 }
 
diff --git a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C
index 7abf63225ada56cf7ebc6ac87a5551d995531325..9a20e12308e08070af7991d0472826058d5f3743 100644
--- a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C
+++ b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2015-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -112,9 +112,8 @@ bool Foam::patchDistMethods::advectionDiffusion::correct
     const fvPatchList& patches = mesh_.boundary();
     volVectorField::Boundary& nybf = ny.boundaryFieldRef();
 
-    forAllConstIter(labelHashSet, patchIDs_, iter)
+    for (const label patchi : patchIDs_)
     {
-        label patchi = iter.key();
         nybf[patchi] == -patches[patchi].nf();
     }
 
diff --git a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/patchDistMethod/patchDistMethodTemplates.C b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/patchDistMethod/patchDistMethodTemplates.C
index 962c8d3927d65b124e01a0c35d90acc2c52ceb1a..012762d2855175cde1c0b8d57b956b978c734027 100644
--- a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/patchDistMethod/patchDistMethodTemplates.C
+++ b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/patchDistMethod/patchDistMethodTemplates.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -40,9 +40,9 @@ Foam::wordList Foam::patchDistMethod::patchTypes
         zeroGradientFvPatchField<Type>::typeName
     );
 
-    forAllConstIter(labelHashSet, patchIDs, iter)
+    for (const label patchi : patchIDs)
     {
-        yTypes[iter.key()] = fixedValueFvPatchField<Type>::typeName;
+        yTypes[patchi] = fixedValueFvPatchField<Type>::typeName;
     }
 
     return yTypes;
diff --git a/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.C b/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.C
index d566133d3c9707fd1910621b583cd8f5fb8539c0..a08fa43b901bede3c6363ee1c5dc9ab60eed48e7 100644
--- a/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.C
+++ b/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2015-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -58,9 +58,8 @@ void Foam::wallDist::constructn() const
 
     volVectorField::Boundary& nbf = n_.ref().boundaryFieldRef();
 
-    forAllConstIter(labelHashSet, patchIDs_, iter)
+    for (const label patchi : patchIDs_)
     {
-        label patchi = iter.key();
         nbf[patchi] == patches[patchi].nf();
     }
 }
diff --git a/src/functionObjects/field/nearWallFields/nearWallFields.C b/src/functionObjects/field/nearWallFields/nearWallFields.C
index 03c1aea82beeb51cff8723271959c4648bdd5001..db0e706b5d7498f3e2f35023ddeb844a4572a877 100644
--- a/src/functionObjects/field/nearWallFields/nearWallFields.C
+++ b/src/functionObjects/field/nearWallFields/nearWallFields.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -48,9 +48,8 @@ void Foam::functionObjects::nearWallFields::calcAddressing()
 {
     // Count number of faces
     label nPatchFaces = 0;
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        label patchi = iter.key();
         nPatchFaces += mesh_.boundary()[patchi].size();
     }
 
@@ -70,9 +69,8 @@ void Foam::functionObjects::nearWallFields::calcAddressing()
     // Add particles to track to sample locations
     nPatchFaces = 0;
 
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        label patchi = iter.key();
         const fvPatch& patch = mesh_.boundary()[patchi];
 
         vectorField nf(patch.nf());
diff --git a/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C b/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C
index 3aba31fa3e0dc9b2944a832bfc819cce591eca69..d16f19232d02f36ee37398f1beef888f76da6120 100644
--- a/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C
+++ b/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -105,10 +105,8 @@ void Foam::functionObjects::nearWallFields::sampleBoundaryField
 
     // Pick up data
     label nPatchFaces = 0;
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        label patchi = iter.key();
-
         fvPatchField<Type>& pfld = fldBf[patchi];
 
         Field<Type> newFld(pfld.size());
diff --git a/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C b/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C
index d5c9e98f70034ce1c93f935ee88977199730a22f..246e5566074ad4abdc0368ac75cc8a1d46cb2fbf 100644
--- a/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C
+++ b/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2013-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -169,25 +169,25 @@ Foam::functionObjects::regionSizeDistribution::findPatchRegions
     const labelHashSet patchIDs(mesh_.boundaryMesh().patchSet(patchNames_));
 
     label nPatchFaces = 0;
-    forAllConstIter(labelHashSet, patchIDs, iter)
+    for (const label patchi : patchIDs)
     {
-        nPatchFaces += mesh_.boundaryMesh()[iter.key()].size();
+        nPatchFaces += mesh_.boundaryMesh()[patchi].size();
     }
 
 
     Map<label> patchRegions(nPatchFaces);
-    forAllConstIter(labelHashSet, patchIDs, iter)
+    for (const label patchi : patchIDs)
     {
-        const polyPatch& pp = mesh_.boundaryMesh()[iter.key()];
+        const polyPatch& pp = mesh_.boundaryMesh()[patchi];
 
         // Collect all regions on the patch
         const labelList& faceCells = pp.faceCells();
 
-        forAll(faceCells, i)
+        for (const label celli : faceCells)
         {
             patchRegions.insert
             (
-                regions[faceCells[i]],
+                regions[celli],
                 Pstream::myProcNo()     // dummy value
             );
         }
@@ -581,10 +581,9 @@ bool Foam::functionObjects::regionSizeDistribution::write()
             << token::TAB << "Volume(mesh)"
             << token::TAB << "Volume(" << alpha.name() << "):"
             << endl;
-        forAllConstIter(Map<label>, patchRegions, iter)
+        for (const label regioni : patchRegions)
         {
-            label regioni = iter.key();
-            Info<< "    " << token::TAB << iter.key()
+            Info<< "    " << token::TAB << regioni
                 << token::TAB << allRegionVolume[regioni]
                 << token::TAB << allRegionAlphaVolume[regioni] << endl;
 
diff --git a/src/functionObjects/field/surfaceInterpolate/surfaceInterpolateTemplates.C b/src/functionObjects/field/surfaceInterpolate/surfaceInterpolateTemplates.C
index 4d845bf535f52bbb320f96aabc468f9a5cab9252..5c4b71e17caa109180a4739b5a27e5f6716fd3f6 100644
--- a/src/functionObjects/field/surfaceInterpolate/surfaceInterpolateTemplates.C
+++ b/src/functionObjects/field/surfaceInterpolate/surfaceInterpolateTemplates.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -36,9 +36,9 @@ void Foam::functionObjects::surfaceInterpolate::interpolateFields()
 
     // Convert field to map
     HashTable<word> fieldMap(2*fieldSet_.size());
-    forAll(fieldSet_, i)
+    for (const auto& namePair : fieldSet_)
     {
-        fieldMap.insert(fieldSet_[i].first(), fieldSet_[i].second());
+        fieldMap.insert(namePair.first(), namePair.second());
     }
 
 
diff --git a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C
index 20f74b8bd5b11963db3c47bc0bb6f7201ab9851d..895a88a0c2a7d0bbc7cde64bb05bd2e6e0ce53da 100644
--- a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C
+++ b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2016-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -171,9 +171,8 @@ bool Foam::functionObjects::wallHeatFlux::read(const dictionary& dict)
     {
         Info<< "    processing wall patches: " << nl;
         labelHashSet filteredPatchSet;
-        forAllConstIter(labelHashSet, patchSet_, iter)
+        for (const label patchi : patchSet_)
         {
-            label patchi = iter.key();
             if (isA<wallPolyPatch>(pbm[patchi]))
             {
                 filteredPatchSet.insert(patchi);
@@ -265,9 +264,8 @@ bool Foam::functionObjects::wallHeatFlux::write()
     const surfaceScalarField::Boundary& magSf =
         mesh_.magSf().boundaryField();
 
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        label patchi = iter.key();
         const fvPatch& pp = patches[patchi];
 
         const scalarField& hfp = wallHeatFlux.boundaryField()[patchi];
diff --git a/src/functionObjects/field/wallShearStress/wallShearStress.C b/src/functionObjects/field/wallShearStress/wallShearStress.C
index 4a33436615a00d0267bfc1887679cfae7d348493..bbf4a3f3940680ef51486818e0e4ea3a4c24838a 100644
--- a/src/functionObjects/field/wallShearStress/wallShearStress.C
+++ b/src/functionObjects/field/wallShearStress/wallShearStress.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2013-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2017-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -65,10 +65,8 @@ void Foam::functionObjects::wallShearStress::calcShearStress
 {
     shearStress.dimensions().reset(Reff.dimensions());
 
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        label patchi = iter.key();
-
         vectorField& ssp = shearStress.boundaryFieldRef()[patchi];
         const vectorField& Sfp = mesh_.Sf().boundaryField()[patchi];
         const scalarField& magSfp = mesh_.magSf().boundaryField()[patchi];
@@ -156,9 +154,8 @@ bool Foam::functionObjects::wallShearStress::read(const dictionary& dict)
     {
         Info<< "    processing wall patches: " << nl;
         labelHashSet filteredPatchSet;
-        forAllConstIter(labelHashSet, patchSet_, iter)
+        for (const label patchi : patchSet_)
         {
-            label patchi = iter.key();
             if (isA<wallPolyPatch>(pbm[patchi]))
             {
                 filteredPatchSet.insert(patchi);
@@ -223,9 +220,8 @@ bool Foam::functionObjects::wallShearStress::write()
 
     const fvPatchList& patches = mesh_.boundary();
 
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        label patchi = iter.key();
         const fvPatch& pp = patches[patchi];
 
         const vectorField& ssp = wallShearStress.boundaryField()[patchi];
diff --git a/src/functionObjects/forces/forces/forces.C b/src/functionObjects/forces/forces/forces.C
index ac7dae98e4758d129f00911e4fda4b9ba59c7297..f1a945b302af34da830047d5f1c7e8450f68ebf0 100644
--- a/src/functionObjects/forces/forces/forces.C
+++ b/src/functionObjects/forces/forces/forces.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -222,9 +222,8 @@ void Foam::functionObjects::forces::initialiseBins()
         // Determine extents of patches
         binMin_ = GREAT;
         scalar binMax = -GREAT;
-        forAllConstIter(labelHashSet, patchSet_, iter)
+        for (const label patchi : patchSet_)
         {
-            label patchi = iter.key();
             const polyPatch& pp = pbm[patchi];
             scalarField d(pp.faceCentres() & binDir_);
             binMin_ = min(min(d), binMin_);
@@ -244,9 +243,8 @@ void Foam::functionObjects::forces::initialiseBins()
                 const porosityModel& pm = *iter();
                 const labelList& cellZoneIDs = pm.cellZoneIDs();
 
-                forAll(cellZoneIDs, i)
+                for (const label zonei : cellZoneIDs)
                 {
-                    label zonei = cellZoneIDs[i];
                     const cellZone& cZone = mesh_.cellZones()[zonei];
                     const scalarField d(dd, cZone);
                     binMin_ = min(min(d), binMin_);
@@ -982,10 +980,8 @@ void Foam::functionObjects::forces::calcForcesMoment()
 
         const surfaceVectorField::Boundary& Sfb = mesh_.Sf().boundaryField();
 
-        forAllConstIter(labelHashSet, patchSet_, iter)
+        for (const label patchi : patchSet_)
         {
-            label patchi = iter.key();
-
             vectorField Md
             (
                 mesh_.C().boundaryField()[patchi] - coordSys_.origin()
@@ -1026,10 +1022,8 @@ void Foam::functionObjects::forces::calcForcesMoment()
         // Scale pRef by density for incompressible simulations
         scalar pRef = pRef_/rho(p);
 
-        forAllConstIter(labelHashSet, patchSet_, iter)
+        for (const label patchi : patchSet_)
         {
-            label patchi = iter.key();
-
             vectorField Md
             (
                 mesh_.C().boundaryField()[patchi] - coordSys_.origin()
@@ -1076,9 +1070,8 @@ void Foam::functionObjects::forces::calcForcesMoment()
 
             const labelList& cellZoneIDs = pm.cellZoneIDs();
 
-            forAll(cellZoneIDs, i)
+            for (const label zonei : cellZoneIDs)
             {
-                label zonei = cellZoneIDs[i];
                 const cellZone& cZone = mesh_.cellZones()[zonei];
 
                 const vectorField d(mesh_.C(), cZone);
diff --git a/src/functionObjects/utilities/ensightWrite/ensightWrite.C b/src/functionObjects/utilities/ensightWrite/ensightWrite.C
index 051bc8f79b918f096855f583f4fafe342f14eee7..c3b927ff97da728f2f4023823abd1a7f047f0864 100644
--- a/src/functionObjects/utilities/ensightWrite/ensightWrite.C
+++ b/src/functionObjects/utilities/ensightWrite/ensightWrite.C
@@ -244,9 +244,9 @@ bool Foam::functionObjects::ensightWrite::write()
         }
     }
 
-    forAllConstIter(wordHashSet, candidates, iter)
+    for (const word& cand : candidates)
     {
-        process(iter.key());
+        process(cand);
     }
 
     Log << " )" << endl;
diff --git a/src/fvAgglomerationMethods/MGridGenGamgAgglomeration/MGridGenGAMGAgglomeration.C b/src/fvAgglomerationMethods/MGridGenGamgAgglomeration/MGridGenGAMGAgglomeration.C
index 7d1833803d328f9cf5dc576a051357697f230eff..9b1834de5d21be44d393cbb67f6777f48aa65dbd 100644
--- a/src/fvAgglomerationMethods/MGridGenGamgAgglomeration/MGridGenGAMGAgglomeration.C
+++ b/src/fvAgglomerationMethods/MGridGenGamgAgglomeration/MGridGenGAMGAgglomeration.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -267,9 +267,8 @@ Foam::MGridGenGAMGAgglomeration::MGridGenGAMGAgglomeration
             //        Should not be. fluke?
             //scalarField weights(*faceWeightsPtr);
             scalarField weights = *magSfPtr;
-            forAllConstIter(labelHashSet, sharedFaces, iter)
+            for (const label facei : sharedFaces)
             {
-                label facei= iter.key();
                 weights[facei] *= 2.0;
             }
 
diff --git a/src/fvMotionSolver/motionDiffusivity/inverseFaceDistance/inverseFaceDistanceDiffusivity.C b/src/fvMotionSolver/motionDiffusivity/inverseFaceDistance/inverseFaceDistanceDiffusivity.C
index 4e005b9e2c30e2ab126aa30dbb367aba0ec5910e..d7e31ade6ef3780735eaa8673529cbc305792c4f 100644
--- a/src/fvMotionSolver/motionDiffusivity/inverseFaceDistance/inverseFaceDistanceDiffusivity.C
+++ b/src/fvMotionSolver/motionDiffusivity/inverseFaceDistance/inverseFaceDistanceDiffusivity.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -75,14 +75,14 @@ void Foam::inverseFaceDistanceDiffusivity::correct()
 
     label nPatchFaces = 0;
 
-    forAll(patchNames_, i)
+    for (const word& patchName : patchNames_)
     {
-        const label pID = bdry.findPatchID(patchNames_[i]);
+        const label patchi = bdry.findPatchID(patchName);
 
-        if (pID > -1)
+        if (patchi >= 0)
         {
-            patchSet.insert(pID);
-            nPatchFaces += bdry[pID].size();
+            patchSet.insert(patchi);
+            nPatchFaces += bdry[patchi].size();
         }
     }
 
@@ -91,9 +91,9 @@ void Foam::inverseFaceDistanceDiffusivity::correct()
 
     nPatchFaces = 0;
 
-    forAllConstIter(labelHashSet, patchSet, iter)
+    for (const label patchi : patchSet)
     {
-        const polyPatch& patch = bdry[iter.key()];
+        const polyPatch& patch = bdry[patchi];
 
         const vectorField::subField fc(patch.faceCentres());
 
diff --git a/src/fvMotionSolver/motionDiffusivity/inversePointDistance/inversePointDistanceDiffusivity.C b/src/fvMotionSolver/motionDiffusivity/inversePointDistance/inversePointDistanceDiffusivity.C
index dc9c801bbe9f2c6d907382ed08f75f88acc167e2..b12fb868c320b3e6c6d62ba1aea49af208bfcdd1 100644
--- a/src/fvMotionSolver/motionDiffusivity/inversePointDistance/inversePointDistanceDiffusivity.C
+++ b/src/fvMotionSolver/motionDiffusivity/inversePointDistance/inversePointDistanceDiffusivity.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -69,9 +69,9 @@ void Foam::inversePointDistanceDiffusivity::correct()
 
     label nPatchEdges = 0;
 
-    forAllConstIter(labelHashSet, patchSet, iter)
+    for (const label patchi : patchSet)
     {
-        nPatchEdges += bdry[iter.key()].nEdges();
+        nPatchEdges += bdry[patchi].nEdges();
     }
 
     // Distance to wall on points and edges.
@@ -88,16 +88,14 @@ void Foam::inversePointDistanceDiffusivity::correct()
 
         nPatchEdges = 0;
 
-        forAllConstIter(labelHashSet, patchSet, iter)
+        for (const label patchi : patchSet)
         {
-            const polyPatch& patch = bdry[iter.key()];
+            const polyPatch& patch = bdry[patchi];
 
             const labelList& meshPoints = patch.meshPoints();
 
-            forAll(meshPoints, i)
+            for (const label pointi : meshPoints)
             {
-                label pointi = meshPoints[i];
-
                 if (!pointWallDist[pointi].valid(dummyTrackData))
                 {
                     // Not yet seeded
@@ -131,7 +129,7 @@ void Foam::inversePointDistanceDiffusivity::correct()
     }
 
 
-    for (label facei=0; facei<mesh().nInternalFaces(); facei++)
+    for (label facei=0; facei<mesh().nInternalFaces(); ++facei)
     {
         const face& f = mesh().faces()[facei];
 
diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C
index 28271824c7cd44783de7a1374d07f5902884231c..98a26202310e22ab913f9061737e3abc6f956a36 100644
--- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C
+++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -234,12 +234,12 @@ void Foam::meshRefinement::calcCellCellRays
 
     forAll(testFaces, i)
     {
-        label facei = testFaces[i];
-        label own = mesh_.faceOwner()[facei];
+        const label facei = testFaces[i];
+        const label own = mesh_.faceOwner()[facei];
 
         if (mesh_.isInternalFace(facei))
         {
-            label nei = mesh_.faceNeighbour()[facei];
+            const label nei = mesh_.faceNeighbour()[facei];
 
             start[i] = cellCentres[own];
             end[i] = cellCentres[nei];
@@ -247,7 +247,7 @@ void Foam::meshRefinement::calcCellCellRays
         }
         else
         {
-            label bFacei = facei - mesh_.nInternalFaces();
+            const label bFacei = facei - mesh_.nInternalFaces();
 
             start[i] = cellCentres[own];
             end[i] = neiCc[bFacei];
@@ -2541,13 +2541,13 @@ void Foam::meshRefinement::updateMesh
     // Update faceToCoupledPatch_
     {
         Map<label> newFaceToPatch(faceToCoupledPatch_.size());
-        forAllConstIter(Map<label>, faceToCoupledPatch_, iter)
+        forAllConstIters(faceToCoupledPatch_, iter)
         {
-            label newFacei = map.reverseFaceMap()[iter.key()];
+            const label newFacei = map.reverseFaceMap()[iter.key()];
 
             if (newFacei >= 0)
             {
-                newFaceToPatch.insert(newFacei, iter());
+                newFaceToPatch.insert(newFacei, iter.object());
             }
         }
         faceToCoupledPatch_.transfer(newFaceToPatch);
diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementMerge.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementMerge.C
index e5df4137334bed2948617183e6c887c724628a6c..21f3e1ba347138b74b7cd780f317cea18e3e54b0 100644
--- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementMerge.C
+++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementMerge.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2014 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -51,11 +51,9 @@ Foam::label Foam::meshRefinement::mergePatchFaces
     // Pick up all candidate cells on boundary
     labelHashSet boundaryCells(mesh_.nFaces()-mesh_.nInternalFaces());
 
-    forAll(patchIDs, i)
+    for (const label patchi : patchIDs)
     {
-        label patchI = patchIDs[i];
-
-        const polyPatch& patch = patches[patchI];
+        const polyPatch& patch = patches[patchi];
 
         if (!patch.coupled())
         {
@@ -221,17 +219,17 @@ Foam::label Foam::meshRefinement::mergePatchFaces
 //
 //        const cellList& cells = mesh_.cells();
 //
-//        forAllConstIter(labelHashSet, retestOldFaces, iter)
+//        for (const label oldFacei : retestOldFaces)
 //        {
-//            label faceI = map().reverseFaceMap()[iter.key()];
+//            const label facei = map().reverseFaceMap()[oldFacei];
 //
-//            const cell& ownFaces = cells[mesh_.faceOwner()[faceI]];
+//            const cell& ownFaces = cells[mesh_.faceOwner()[facei]];
 //
 //            retestFaces.insertMany(ownFaces);
 //
-//            if (mesh_.isInternalFace(faceI))
+//            if (mesh_.isInternalFace(facei))
 //            {
-//                const cell& neiFaces = cells[mesh_.faceNeighbour()[faceI]];
+//                const cell& neiFaces = cells[mesh_.faceNeighbour()[facei]];
 //
 //                retestFaces.insertMany(neiFaces);
 //            }
@@ -579,7 +577,7 @@ Foam::label Foam::meshRefinement::mergePatchFacesUndo
             // (unless the faces are absolutely planar)
             labelHashSet retestFaces(2*restoredFaces.size());
 
-            forAllConstIter(Map<label>, restoredFaces, iter)
+            forAllConstIters(restoredFaces, iter)
             {
                 retestFaces.insert(iter.key());
             }
@@ -656,12 +654,11 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::doRemovePoints
 
     // Retest all affected faces and all the cells using them
     labelHashSet retestFaces(pointRemover.savedFaceLabels().size());
-    forAll(pointRemover.savedFaceLabels(), i)
+    for (const label facei : pointRemover.savedFaceLabels())
     {
-        label faceI = pointRemover.savedFaceLabels()[i];
-        if (faceI >= 0)
+        if (facei >= 0)
         {
-            retestFaces.insert(faceI);
+            retestFaces.insert(facei);
         }
     }
     updateMesh(map, growFaceCellFace(retestFaces));
@@ -761,13 +758,11 @@ Foam::labelList Foam::meshRefinement::collectFaces
     // Has face been selected?
     boolList selected(mesh_.nFaces(), false);
 
-    forAll(candidateFaces, i)
+    for (const label facei : candidateFaces)
     {
-        label faceI = candidateFaces[i];
-
-        if (set.found(faceI))
+        if (set.found(facei))
         {
-            selected[faceI] = true;
+            selected[facei] = true;
         }
     }
     syncTools::syncFaceList
@@ -797,9 +792,9 @@ namespace Foam
         const label own = pMesh.faceOwner()[faceI];
 
         const cell& ownFaces = pMesh.cells()[own];
-        forAll(ownFaces, ownFaceI)
+        for (const label facei : ownFaces)
         {
-            selected[ownFaces[ownFaceI]] = true;
+            selected[facei] = true;
         }
 
         if (pMesh.isInternalFace(faceI))
@@ -824,9 +819,9 @@ Foam::labelList Foam::meshRefinement::growFaceCellFace
 {
     boolList selected(mesh_.nFaces(), false);
 
-    for (auto faceI : set)
+    for (const label facei : set)
     {
-        markGrowFaceCellFace(mesh_, faceI, selected);
+        markGrowFaceCellFace(mesh_, facei, selected);
     }
 
     syncTools::syncFaceList
@@ -847,10 +842,9 @@ Foam::labelList Foam::meshRefinement::growFaceCellFace
 {
     boolList selected(mesh_.nFaces(), false);
 
-    forAllConstIter(labelHashSet, set, iter)
+    for (const label facei : set)
     {
-        const label faceI = iter.key();
-        markGrowFaceCellFace(mesh_, faceI, selected);
+        markGrowFaceCellFace(mesh_, facei, selected);
     }
 
     syncTools::syncFaceList
diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C
index 69740b95ba6c9022519359b8f50340227d7e1926..9a6fe089dfa611a29d4a7a14179a3d1aaa2ab141 100644
--- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C
+++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -57,16 +57,16 @@ void Foam::meshRefinement::markBoundaryFace
 
     const labelList& fEdges = mesh_.faceEdges(facei);
 
-    forAll(fEdges, fp)
+    for (const label edgei : fEdges)
     {
-        isBoundaryEdge[fEdges[fp]] = true;
+        isBoundaryEdge[edgei] = true;
     }
 
     const face& f = mesh_.faces()[facei];
 
-    forAll(f, fp)
+    for (const label pointi : f)
     {
-        isBoundaryPoint[f[fp]] = true;
+        isBoundaryPoint[pointi] = true;
     }
 }
 
@@ -551,7 +551,7 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
         );
 
         // Baffle all faces of cells that need to be removed
-        forAllConstIter(Map<label>, problemCells, iter)
+        forAllConstIters(problemCells, iter)
         {
             const cell& cFaces = mesh_.cells()[iter.key()];
 
@@ -832,30 +832,26 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
 
     DynamicList<label> dynPCells;
 
-    forAllConstIter(labelHashSet, nonBoundaryAnchors, iter)
+    for (const label pointi : nonBoundaryAnchors)
     {
-        label pointi = iter.key();
-
         const labelList& pCells = mesh_.pointCells(pointi, dynPCells);
 
         // Count number of 'hasSevenBoundaryAnchorPoints' cells.
         label n = 0;
 
-        forAll(pCells, i)
+        for (const label celli : pCells)
         {
-            if (hasSevenBoundaryAnchorPoints.test(pCells[i]))
+            if (hasSevenBoundaryAnchorPoints.test(celli))
             {
-                n++;
+                ++n;
             }
         }
 
         if (n > 3)
         {
             // Point in danger of being what? Remove all 7-cells.
-            forAll(pCells, i)
+            for (const label celli : pCells)
             {
-                label celli = pCells[i];
-
                 if (hasSevenBoundaryAnchorPoints.test(celli))
                 {
                     if
@@ -878,10 +874,8 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
                     {
                         const cell& cFaces = mesh_.cells()[celli];
 
-                        forAll(cFaces, cf)
+                        for (const label facei : cFaces)
                         {
-                            label facei = cFaces[cf];
-
                             if
                             (
                                 facePatch[facei] == -1
@@ -943,11 +937,11 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
             const labelList& fEdges = mesh_.faceEdges(facei, dynFEdges);
             label nFaceBoundaryEdges = 0;
 
-            forAll(fEdges, fe)
+            for (const label edgei : fEdges)
             {
-                if (isBoundaryEdge[fEdges[fe]])
+                if (isBoundaryEdge[edgei])
                 {
-                    nFaceBoundaryEdges++;
+                    ++nFaceBoundaryEdges;
                 }
             }
 
@@ -985,10 +979,8 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
         }
     }
 
-    forAll(patches, patchi)
+    for (const polyPatch& pp : patches)
     {
-        const polyPatch& pp = patches[patchi];
-
         if (pp.coupled())
         {
             label facei = pp.start();
@@ -1000,11 +992,11 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
                     const labelList& fEdges = mesh_.faceEdges(facei, dynFEdges);
                     label nFaceBoundaryEdges = 0;
 
-                    forAll(fEdges, fe)
+                    for (const label edgei : fEdges)
                     {
-                        if (isBoundaryEdge[fEdges[fe]])
+                        if (isBoundaryEdge[edgei])
                         {
-                            nFaceBoundaryEdges++;
+                            ++nFaceBoundaryEdges;
                         }
                     }
 
diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/layerParameters/layerParameters.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/layerParameters/layerParameters.C
index 92e773bcc5aefab62563e97ce9020ac2e88f3c1d..64500d2b853b67bf843cc526e1720328df55acc1 100644
--- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/layerParameters/layerParameters.C
+++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/layerParameters/layerParameters.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -280,10 +280,8 @@ Foam::layerParameters::layerParameters
             {
                 const dictionary& layerDict = iter().dict();
 
-                forAllConstIter(labelHashSet, patchIDs, patchiter)
+                for (const label patchi : patchIDs)
                 {
-                    label patchi = patchiter.key();
-
                     numLayers_[patchi] =
                         readLabel(layerDict.lookup("nSurfaceLayers"));
 
diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C
index a68854cc1edc686de6f86ddd1408b8630ab84482..51da101189b7183e248a1ada8328fb02755f5145 100644
--- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C
+++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -1074,7 +1074,7 @@ Foam::label Foam::snappyRefineDriver::refinementInterfaceRefine
 
                 //forAllConstIter(cellSet, transitionCells, iter)
                 //{
-                //    label celli = iter.key();
+                //    const label celli : iter.key();
                 //    const cell& cFaces = cells[celli];
                 //    const point& cc = cellCentres[celli];
                 //    const scalar rCVol = pow(cellVolumes[celli], -5.0/3.0);
@@ -1859,10 +1859,10 @@ void Foam::snappyRefineDriver::addFaceZones
         const polyMesh& mesh = meshRefiner.mesh();
 
         // Add patches for added inter-region faceZones
-        forAllConstIter(HashTable<Pair<word>>, faceZoneToPatches, iter)
+        forAllConstIters(faceZoneToPatches, iter)
         {
             const word& fzName = iter.key();
-            const Pair<word>& patchNames = iter();
+            const Pair<word>& patchNames = iter.object();
 
             // Get any user-defined faceZone data
             surfaceZonesInfo::faceZoneType fzType;
diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C
index fcbe2737070e3de5699da982fcc7d1d658a1b9c9..266489c717d2852e7b1d64cf721f3f37148fba0a 100644
--- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C
+++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2013-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -425,10 +425,9 @@ restartUncoveredSourceFace
         // list of faces currently visited for srcFacei to avoid multiple hits
         DynamicList<label> visitedFaces(10);
 
-        forAllConstIter(labelHashSet, lowWeightFaces, iter)
+        for (const label srcFacei : lowWeightFaces)
         {
-            label srcFacei = iter.key();
-            label tgtFacei = this->findTargetFace(srcFacei);
+            const label tgtFacei = this->findTargetFace(srcFacei);
             if (tgtFacei != -1)
             {
                 //bool faceProcessed =
diff --git a/src/meshTools/algorithms/PatchEdgeFaceWave/patchPatchDist.C b/src/meshTools/algorithms/PatchEdgeFaceWave/patchPatchDist.C
index 24d210eadbd78c6144bddf23ce591c85b008607d..6477a5d4e5e44781b4f50cd9326e7ca10309b7ce 100644
--- a/src/meshTools/algorithms/PatchEdgeFaceWave/patchPatchDist.C
+++ b/src/meshTools/algorithms/PatchEdgeFaceWave/patchPatchDist.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -57,9 +57,8 @@ void Foam::patchPatchDist::correct()
 {
     // Mark all edge connected to a nbrPatch.
     label nBnd = 0;
-    forAllConstIter(labelHashSet, nbrPatchIDs_, iter)
+    for (const label nbrPatchi : nbrPatchIDs_)
     {
-        label nbrPatchi = iter.key();
         const polyPatch& nbrPatch = patch_.boundaryMesh()[nbrPatchi];
         nBnd += nbrPatch.nEdges()-nbrPatch.nInternalEdges();
     }
@@ -68,9 +67,8 @@ void Foam::patchPatchDist::correct()
     // functionality for these.
     EdgeMap<label> nbrEdges(2*nBnd);
 
-    forAllConstIter(labelHashSet, nbrPatchIDs_, iter)
+    for (const label nbrPatchi : nbrPatchIDs_)
     {
-        label nbrPatchi = iter.key();
         const polyPatch& nbrPatch = patch_.boundaryMesh()[nbrPatchi];
         const labelList& nbrMp = nbrPatch.meshPoints();
 
@@ -78,7 +76,7 @@ void Foam::patchPatchDist::correct()
         (
             label edgeI = nbrPatch.nInternalEdges();
             edgeI < nbrPatch.nEdges();
-            edgeI++
+            ++edgeI
         )
         {
             const edge& e = nbrPatch.edges()[edgeI];
diff --git a/src/meshTools/cellClassification/cellClassification.C b/src/meshTools/cellClassification/cellClassification.C
index 3a26f9785166b9562c1175fdb81a71cdbd8ea628..cac1a2449962cbd05aaffb19e559f1284fd10886 100644
--- a/src/meshTools/cellClassification/cellClassification.C
+++ b/src/meshTools/cellClassification/cellClassification.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -805,7 +805,7 @@ Foam::label Foam::cellClassification::fillRegionPoints
 {
     label nTotChanged = 0;
 
-    for (label iter = 0; iter < maxIter; iter++)
+    for (label iter = 0; iter < maxIter; ++iter)
     {
         // Get interface between meshType cells and non-meshType cells as a list
         // of faces and for each face the cell which is the meshType.
@@ -826,26 +826,25 @@ Foam::label Foam::cellClassification::fillRegionPoints
 
         label nChanged = 0;
 
-        forAllConstIter(labelHashSet, nonManifoldPoints, iter)
+        for (const label nonManPti : nonManifoldPoints)
         {
             // Find a face on fp using point and remove it.
-            const label patchPointi = meshPointMap[iter.key()];
+            const label patchPointi = meshPointMap[nonManPti];
 
             const labelList& pFaces = fp.pointFaces()[patchPointi];
 
             // Remove any face using conflicting point. Does first face which
             // has not yet been done. Could be more intelligent and decide which
             // one would be best to remove.
-            forAll(pFaces, i)
+            for (const label patchFacei : pFaces)
             {
-                const label patchFacei = pFaces[i];
                 const label ownerCell  = outsideOwner[patchFacei];
 
                 if (operator[](ownerCell) == meshType)
                 {
                     operator[](ownerCell) = fillType;
 
-                    nChanged++;
+                    ++nChanged;
                     break;
                 }
             }
diff --git a/src/meshTools/sets/faceSources/patchToFace/patchToFace.C b/src/meshTools/sets/faceSources/patchToFace/patchToFace.C
index acbef6688640dc65d25269a5b87e3000a9d59bf5..26f7d7459c5a640ca2125567a9b5629411e8604b 100644
--- a/src/meshTools/sets/faceSources/patchToFace/patchToFace.C
+++ b/src/meshTools/sets/faceSources/patchToFace/patchToFace.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -61,10 +61,8 @@ void Foam::patchToFace::combine(topoSet& set, const bool add) const
         true            // use patch groups if available
     );
 
-    forAllConstIter(labelHashSet, patchIDs, iter)
+    for (const label patchi : patchIDs)
     {
-        label patchi = iter.key();
-
         const polyPatch& pp = mesh_.boundaryMesh()[patchi];
 
         Info<< "    Found matching patch " << pp.name()
diff --git a/src/meshTools/sets/topoSets/topoSet.C b/src/meshTools/sets/topoSets/topoSet.C
index fc4ddd2e192b6f5042b1df7e7d1e5d5c2d621cbd..8caf02d3ba62f9c0f6821de11973f4ce326f04cb 100644
--- a/src/meshTools/sets/topoSets/topoSet.C
+++ b/src/meshTools/sets/topoSets/topoSet.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -136,23 +136,24 @@ void Foam::topoSet::updateLabels(const labelList& map)
     // Iterate over map to see if anything changed
     bool changed = false;
 
-    forAllConstIter(labelHashSet, *this, iter)
+    const labelHashSet& labels = *this;
+
+    for (const label oldId : labels)
     {
-        if ((iter.key() < 0) || (iter.key() > map.size()))
+        if (oldId < 0 || oldId > map.size())
         {
             FatalErrorInFunction
-                << "Illegal content " << iter.key() << " of set:" << name()
+                << "Illegal content " << oldId << " of set:" << name()
                 << " of type " << type() << endl
-                << "Value should be between 0 and " << map.size()-1
+                << "Value should be between [0," << map.size() << ')'
                 << abort(FatalError);
         }
 
-        const label newCelli = map[iter.key()];
+        const label newId = map[oldId];
 
-        if (newCelli != iter.key())
+        if (newId != oldId)
         {
             changed = true;
-
             break;
         }
     }
@@ -162,13 +163,13 @@ void Foam::topoSet::updateLabels(const labelList& map)
     {
         labelHashSet newSet(2*size());
 
-        forAllConstIter(labelHashSet, *this, iter)
+        for (const label oldId : labels)
         {
-            const label newCelli = map[iter.key()];
+            const label newId = map[oldId];
 
-            if (newCelli >= 0)
+            if (newId >= 0)
             {
-                newSet.insert(newCelli);
+                newSet.insert(newId);
             }
         }
 
@@ -179,14 +180,16 @@ void Foam::topoSet::updateLabels(const labelList& map)
 
 void Foam::topoSet::check(const label maxLabel)
 {
-    forAllConstIter(topoSet, *this, iter)
+    const labelHashSet& labels = *this;
+
+    for (const label oldId : labels)
     {
-        if ((iter.key() < 0) || (iter.key() > maxLabel))
+        if (oldId < 0 || oldId > maxLabel)
         {
             FatalErrorInFunction
-                << "Illegal content " << iter.key() << " of set:" << name()
-                << " of type " << type() << endl
-                << "Value should be between 0 and " << maxLabel
+                << "Illegal content " << oldId << " of set:" << name()
+                << " of type " << type() << nl
+                << "Value should be between [0," << maxLabel << ']'
                 << abort(FatalError);
         }
     }
@@ -206,14 +209,14 @@ void Foam::topoSet::writeDebug
 
     for (; (iter != end()) && (n < maxElem); ++iter)
     {
-        if ((n != 0) && ((n % 10) == 0))
+        if (n && ((n % 10) == 0))
         {
             os << endl;
         }
         os << iter.key() << ' ';
 
-        n++;
-        elemI++;
+        ++n;
+        ++elemI;
     }
 }
 
@@ -232,14 +235,14 @@ void Foam::topoSet::writeDebug
 
     for (; (iter != end()) && (n < maxElem); ++iter)
     {
-        if ((n != 0) && ((n % 3) == 0))
+        if (n && ((n % 3) == 0))
         {
             os << endl;
         }
         os << iter.key() << coords[iter.key()] << ' ';
 
-        n++;
-        elemI++;
+        ++n;
+        ++elemI;
     }
 }
 
@@ -488,12 +491,12 @@ void Foam::topoSet::subset(const topoSet& set)
     clear();
     resize(2*min(currentSet.size(), set.size()));
 
-    forAllConstIter(labelHashSet, currentSet, iter)
+    for (const label currId : currentSet)
     {
-        if (set.found(iter.key()))
+        if (set.found(currId))
         {
             // element present in both currentSet and set.
-            insert(iter.key());
+            insert(currId);
         }
     }
 }
@@ -501,18 +504,20 @@ void Foam::topoSet::subset(const topoSet& set)
 
 void Foam::topoSet::addSet(const topoSet& set)
 {
-    forAllConstIter(topoSet, set, iter)
+    const labelHashSet& labels = set;
+    for (const label id : labels)
     {
-        insert(iter.key());
+        insert(id);
     }
 }
 
 
 void Foam::topoSet::deleteSet(const topoSet& set)
 {
-    forAllConstIter(topoSet, set, iter)
+    const labelHashSet& labels = set;
+    for (const label id : labels)
     {
-        erase(iter.key());
+        erase(id);
     }
 }
 
diff --git a/src/meshTools/surfaceSets/surfaceSets.C b/src/meshTools/surfaceSets/surfaceSets.C
index d2b7106ab071765f03ed9aa6c5da4877a2cec03e..9309e963ece4571111f2a31d714436a732383b52 100644
--- a/src/meshTools/surfaceSets/surfaceSets.C
+++ b/src/meshTools/surfaceSets/surfaceSets.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -121,18 +121,16 @@ License
 //    // Snap outside points to surface
 //    pointField newPoints(points);
 //
-//    forAllConstIter(labelHashSet, flatCandidates, iter)
+//    for (const label celli : flatCandidates)
 //    {
-//        const cell& cFaces = cells[iter.key()];
+//        const cell& cFaces = cells[celli];
 //
-//        forAll(cFaces, cFacei)
+//        for (const label facei : cFaces)
 //        {
-//            const face& f = faces[cFaces[cFacei]];
+//            const face& f = faces[facei];
 //
-//            forAll(f, fp)
+//            for (const label pointi : f)
 //            {
-//                label pointi = f[fp];
-//
 //                if (outsidePoints.insert(pointi))
 //                {
 //                    // Calculate new position for this outside point
@@ -147,10 +145,8 @@ License
 //
 //    // Calculate new volume for mixed cells
 //    label nRemoved = 0;
-//    forAllConstIter(labelHashSet, flatCandidates, iter)
+//    for (const label celli : flatCandidates)
 //    {
-//        label celli = iter.key();
-//
 //        const cell& cll = cells[celli];
 //
 //        scalar newVol = cll.mag(newPoints, faces);
@@ -374,20 +370,19 @@ Foam::labelHashSet Foam::surfaceSets::getHangingCells
 
     labelHashSet mixedOnlyCells(internalCells.size());
 
-    forAllConstIter(labelHashSet, internalCells, iter)
+    for (const label celli : internalCells)
     {
-        const label celli = iter.key();
         const cell& cFaces = cells[celli];
 
         label usesMixedOnly = true;
 
-        forAll(cFaces, i)
+        for (const label facei : cFaces)
         {
-            const face& f = faces[cFaces[i]];
+            const face& f = faces[facei];
 
-            forAll(f, fp)
+            for (const label pointi : f)
             {
-                if (pointSide[f[fp]] != MIXED)
+                if (pointSide[pointi] != MIXED)
                 {
                     usesMixedOnly = false;
                     break;
diff --git a/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C b/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C
index 8a2436733aaa8f2bb33b9fcf592d13972a3ed7b3..1aaf5824f718fc9b1742a414c70e7c445c5b6d45 100644
--- a/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C
+++ b/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -2294,31 +2294,26 @@ Foam::triSurface Foam::triSurfaceTools::triangulate
 
     label newPatchi = 0;
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchi : includePatches)
     {
-        const label patchi = iter.key();
         const polyPatch& patch = bMesh[patchi];
         const pointField& points = patch.points();
 
         label nTriTotal = 0;
 
-        forAll(patch, patchFacei)
+        for (const face& f :  patch)
         {
-            const face& f = patch[patchFacei];
-
             faceList triFaces(f.nTriangles(points));
 
             label nTri = 0;
 
             f.triangles(points, nTri, triFaces);
 
-            forAll(triFaces, triFacei)
+            for (const face& f :  triFaces)
             {
-                const face& f = triFaces[triFacei];
-
                 triangles.append(labelledTri(f[0], f[1], f[2], newPatchi));
 
-                nTriTotal++;
+                ++nTriTotal;
             }
         }
 
@@ -2348,9 +2343,8 @@ Foam::triSurface Foam::triSurfaceTools::triangulate
 
     newPatchi = 0;
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchi : includePatches)
     {
-        const label patchi = iter.key();
         const polyPatch& patch = bMesh[patchi];
 
         surface.patches()[newPatchi].name() = patch.name();
@@ -2399,9 +2393,8 @@ Foam::triSurface Foam::triSurfaceTools::triangulateFaceCentre
 
     label newPatchi = 0;
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchi : includePatches)
     {
-        const label patchi = iter.key();
         const polyPatch& patch = bMesh[patchi];
 
         label nTriTotal = 0;
@@ -2451,9 +2444,8 @@ Foam::triSurface Foam::triSurfaceTools::triangulateFaceCentre
 
     newPatchi = 0;
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchi : includePatches)
     {
-        const label patchi = iter.key();
         const polyPatch& patch = bMesh[patchi];
 
         surface.patches()[newPatchi].name() = patch.name();
diff --git a/src/regionModels/surfaceFilmModels/submodels/kinematic/force/contactAngleForces/contactAngleForce/contactAngleForce.C b/src/regionModels/surfaceFilmModels/submodels/kinematic/force/contactAngleForces/contactAngleForce/contactAngleForce.C
index 2d8f8e76f8e8c5d01ce49bedb8da765edda1bbd7..53419d5b3401171ec7f8e063c80c5ac6eaf4573e 100644
--- a/src/regionModels/surfaceFilmModels/submodels/kinematic/force/contactAngleForces/contactAngleForce/contactAngleForce.C
+++ b/src/regionModels/surfaceFilmModels/submodels/kinematic/force/contactAngleForces/contactAngleForce/contactAngleForce.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -61,9 +61,8 @@ void contactAngleForce::initialise()
 
         labelHashSet patchIDs = pbm.patchSet(zeroForcePatches);
 
-        forAllConstIter(labelHashSet, patchIDs, iter)
+        for (const label patchi : patchIDs)
         {
-            label patchi = iter.key();
             Info<< "            " << pbm[patchi].name() << endl;
         }
 
diff --git a/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/injectionModelList/injectionModelList.C b/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/injectionModelList/injectionModelList.C
index 166702793337a5479d403abdd1a5292e84330647..e9770089d27ce5a627e857ce759a7015e43c327c 100644
--- a/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/injectionModelList/injectionModelList.C
+++ b/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/injectionModelList/injectionModelList.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -65,7 +65,7 @@ injectionModelList::injectionModelList
     wordHashSet models(activeModels);
 
     Info<< "    Selecting film injection models" << endl;
-    if (models.size() > 0)
+    if (models.size())
     {
         this->setSize(models.size());
 
diff --git a/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/patchInjection/patchInjection.C b/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/patchInjection/patchInjection.C
index 69c34d9bfc58a8fa87b4bcd8b200ee04d95efbd2..101af50c22f1e60ba233c89d77503053a4801974 100644
--- a/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/patchInjection/patchInjection.C
+++ b/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/patchInjection/patchInjection.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2015-2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -65,9 +65,8 @@ patchInjection::patchInjection
         Info<< "        applying to patches:" << nl;
 
         label pidi = 0;
-        forAllConstIter(labelHashSet, patchSet, iter)
+        for (const label patchi : patchSet)
         {
-            label patchi = iter.key();
             patchIDs_[pidi++] = patchi;
             Info<< "            " << pbm[patchi].name() << endl;
         }
diff --git a/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C b/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C
index c936e0b753ef3446fd3af109052c2fef15b206cc..8c2ffc0014ebb48fd4cab6a60e84eda0b7328151 100644
--- a/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C
+++ b/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2012-2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -150,9 +150,9 @@ Foam::labelList Foam::structuredRenumber::renumber
     const labelHashSet patchIDs(pbm.patchSet(patches_));
 
     label nFaces = 0;
-    forAllConstIter(labelHashSet, patchIDs, iter)
+    for (const label patchi : patchIDs)
     {
-        nFaces += pbm[iter.key()].size();
+        nFaces += pbm[patchi].size();
     }
 
 
@@ -205,9 +205,9 @@ Foam::labelList Foam::structuredRenumber::renumber
     labelList patchFaces(nFaces);
     List<topoDistanceData> patchData(nFaces);
     nFaces = 0;
-    forAllConstIter(labelHashSet, patchIDs, iter)
+    for (const label patchi : patchIDs)
     {
-        const polyPatch& pp = pbm[iter.key()];
+        const polyPatch& pp = pbm[patchi];
         const labelUList& fc = pp.faceCells();
         forAll(fc, i)
         {
diff --git a/src/rigidBodyMeshMotion/rigidBodyMeshMotionSolver/rigidBodyMeshMotionSolver.C b/src/rigidBodyMeshMotion/rigidBodyMeshMotionSolver/rigidBodyMeshMotionSolver.C
index 2afa94937bf44860528d533a93404ef007a20e15..db42001702ada0ed9386c6b9a568f1a6a860b329 100644
--- a/src/rigidBodyMeshMotion/rigidBodyMeshMotionSolver/rigidBodyMeshMotionSolver.C
+++ b/src/rigidBodyMeshMotion/rigidBodyMeshMotionSolver/rigidBodyMeshMotionSolver.C
@@ -247,10 +247,8 @@ void Foam::rigidBodyMeshMotionSolver::solve()
     // Update the displacements
     forAll(bodyMeshes_, bi)
     {
-        forAllConstIter(labelHashSet, bodyMeshes_[bi].patchSet_, iter)
+        for (const label patchi : bodyMeshes_[bi].patchSet_)
         {
-            label patchi = iter.key();
-
             pointField patchPoints0
             (
                 meshSolver_.pointDisplacement().boundaryField()[patchi]
diff --git a/src/sampling/meshToMesh/meshToMesh.C b/src/sampling/meshToMesh/meshToMesh.C
index 8fce5248eb3fe3fa5cd3fe6a71e1d54ff32608b1..1db2b8cc295e2c1b84378563030deb0b30df50c7 100644
--- a/src/sampling/meshToMesh/meshToMesh.C
+++ b/src/sampling/meshToMesh/meshToMesh.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2012-2017 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -790,10 +790,10 @@ void Foam::meshToMesh::constructFromCuttingPatches
     DynamicList<label> srcIDs(patchMap.size());
     DynamicList<label> tgtIDs(patchMap.size());
 
-    forAllConstIter(HashTable<word>, patchMap, iter)
+    forAllConstIters(patchMap, iter)
     {
         const word& tgtPatchName = iter.key();
-        const word& srcPatchName = iter();
+        const word& srcPatchName = iter.object();
 
         const polyPatch& srcPatch = srcBm[srcPatchName];
 
diff --git a/src/sampling/sampledSet/patchCloud/patchCloudSet.C b/src/sampling/sampledSet/patchCloud/patchCloudSet.C
index 8c5264dad5907ebe9f68d1d77e8d5f31f063bcd7..12c0b4a8df8659f85cd6c8268e690bc962b4520f 100644
--- a/src/sampling/sampledSet/patchCloud/patchCloudSet.C
+++ b/src/sampling/sampledSet/patchCloud/patchCloudSet.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2017-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -60,9 +60,9 @@ void Foam::patchCloudSet::calcSamples
 
     // Construct search tree for all patch faces.
     label sz = 0;
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
+        const polyPatch& pp = mesh().boundaryMesh()[patchi];
 
         sz += pp.size();
 
@@ -75,9 +75,9 @@ void Foam::patchCloudSet::calcSamples
     labelList patchFaces(sz);
     sz = 0;
     treeBoundBox bb(boundBox::invertedBox);
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
+        const polyPatch& pp = mesh().boundaryMesh()[patchi];
 
         forAll(pp, i)
         {
diff --git a/src/sampling/sampledSet/patchSeed/patchSeedSet.C b/src/sampling/sampledSet/patchSeed/patchSeedSet.C
index 53c61f5abb5396fa5e72d753406281cb5696c045..4ecb3761d616fcbb0b6a0bdbb0728a50869c1960 100644
--- a/src/sampling/sampledSet/patchSeed/patchSeedSet.C
+++ b/src/sampling/sampledSet/patchSeed/patchSeedSet.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2012-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -60,9 +60,9 @@ void Foam::patchSeedSet::calcSamples
 
     // Construct search tree for all patch faces.
     label sz = 0;
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
+        const polyPatch& pp = mesh().boundaryMesh()[patchi];
 
         sz += pp.size();
 
@@ -74,9 +74,9 @@ void Foam::patchSeedSet::calcSamples
 
     labelList patchFaces(sz);
     sz = 0;
-    forAllConstIter(labelHashSet, patchSet_, iter)
+    for (const label patchi : patchSet_)
     {
-        const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
+        const polyPatch& pp = mesh().boundaryMesh()[patchi];
         forAll(pp, i)
         {
             patchFaces[sz++] = pp.start()+i;
diff --git a/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C b/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C
index f0602d80fc6d1036820fa64c3031eda4936b7ba4..fcc79c3449904ee9970ed0939c1c75a5c94b939f 100644
--- a/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C
+++ b/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2017-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -87,25 +87,17 @@ Foam::triSurface Foam::faceShading::triangulate
 
     label newPatchI = 0;
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchI : includePatches)
     {
-        const label patchI = iter.key();
         const polyPatch& patch = bMesh[patchI];
         const pointField& points = patch.points();
 
         label nTriTotal = 0;
 
-        if (includeAllFacesPerPatch[patchI].size() > 0)
+        if (includeAllFacesPerPatch[patchI].size())
         {
-            forAllConstIter
-            (
-                labelHashSet,
-                includeAllFacesPerPatch[patchI],
-                iter1
-            )
+            for (const label patchFaceI : includeAllFacesPerPatch[patchI])
             {
-                const label patchFaceI = iter1.key();
-
                 const face& f = patch[patchFaceI];
 
                 faceList triFaces(f.nTriangles(points));
@@ -146,12 +138,11 @@ Foam::triSurface Foam::faceShading::triangulate
 
     newPatchI = 0;
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchI : includePatches)
     {
-        const label patchI = iter.key();
         const polyPatch& patch = bMesh[patchI];
 
-        if (includeAllFacesPerPatch[patchI].size() > 0)
+        if (includeAllFacesPerPatch[patchI].size())
         {
             surface.patches()[newPatchI].name() = patch.name();
             surface.patches()[newPatchI].geometricType() = patch.type();
diff --git a/src/thermophysicalModels/radiation/radiationModels/solarLoad/solarLoad.C b/src/thermophysicalModels/radiation/radiationModels/solarLoad/solarLoad.C
index d6da35329dac2b58c73a23b4ab698712fc27bdbd..4dd450145c955c5ae37919bfc3b6072cfc8124c2 100644
--- a/src/thermophysicalModels/radiation/radiationModels/solarLoad/solarLoad.C
+++ b/src/thermophysicalModels/radiation/radiationModels/solarLoad/solarLoad.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -98,9 +98,8 @@ void Foam::radiation::solarLoad::updateAbsorptivity
     const boundaryRadiationProperties& boundaryRadiation =
         boundaryRadiationProperties::New(mesh_);
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchID : includePatches)
     {
-        const label patchID = iter.key();
         absorptivity_[patchID].setSize(nBands_);
         for (label bandI = 0; bandI < nBands_; bandI++)
         {
@@ -174,9 +173,8 @@ void Foam::radiation::solarLoad::updateSkyDiffusiveRadiation
         case solarCalculator::mSunLoadFairWeatherConditions:
         case solarCalculator::mSunLoadTheoreticalMaximum:
         {
-            forAllConstIter(labelHashSet, includePatches, iter)
+            for (const label patchID : includePatches)
             {
-                const label patchID = iter.key();
                 const polyPatch& pp = patches[patchID];
                 const scalarField& sf = mesh_.magSf().boundaryField()[patchID];
 
@@ -255,9 +253,8 @@ void Foam::radiation::solarLoad::updateSkyDiffusiveRadiation
 
         case solarCalculator::mSunLoadConstant:
         {
-            forAllConstIter(labelHashSet, includePatches, iter)
+            for (const label patchID : includePatches)
             {
-                const label patchID = iter.key();
                 const polyPatch& pp = patches[patchID];
                 const scalarField& sf = mesh_.magSf().boundaryField()[patchID];
 
@@ -589,9 +586,8 @@ void Foam::radiation::solarLoad::calculateQdiff
     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
     volScalarField::Boundary& qrBf = qr_.boundaryFieldRef();
 
-    forAllConstIter(labelHashSet, includePatches, iter)
+    for (const label patchID : includePatches)
     {
-        const label patchID = iter.key();
         const scalarField& qSecond = qsecondRad_.boundaryField()[patchID];
         if (includeMappedPatchBasePatches[patchID])
         {