From da723ce0488429e0b42c43c6240a2d7a29eef410 Mon Sep 17 00:00:00 2001
From: Julian Heinze <julian.heinze@ufz.de>
Date: Tue, 25 Jul 2023 14:53:10 +0200
Subject: [PATCH] std::any_of instead of for-loop

---
 .../MeshGenerators/AddFaultToVoxelGrid.cpp    | 25 ++++++++++---------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp b/MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp
index a0d1089629d..7a0bd6be3b3 100644
--- a/MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp
+++ b/MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp
@@ -167,22 +167,23 @@ bool isVoxelGrid(MeshLib::Mesh const& mesh)
             "aligned hexahedra).");
         return false;
     }
-
-    for (auto const& e : elements)
+    auto is_voxel = [](auto const& e)
     {
         auto const n = e->getNodes();
-        if ((*n[0])[2] != (*n[1])[2] || (*n[1])[2] != (*n[2])[2] ||
-            (*n[4])[2] != (*n[5])[2] || (*n[5])[2] != (*n[6])[2] ||
-            (*n[1])[0] != (*n[2])[0] || (*n[2])[0] != (*n[5])[0] ||
-            (*n[0])[0] != (*n[3])[0] || (*n[3])[0] != (*n[7])[0])
-        {
-            ERR("Input mesh needs to be voxel grid (i.e. equally sized axis "
-                "aligned hexahedra).");
-            return false;
-        }
+        return ((*n[0])[2] != (*n[1])[2] || (*n[1])[2] != (*n[2])[2] ||
+                (*n[4])[2] != (*n[5])[2] || (*n[5])[2] != (*n[6])[2] ||
+                (*n[1])[0] != (*n[2])[0] || (*n[2])[0] != (*n[5])[0] ||
+                (*n[0])[0] != (*n[3])[0] || (*n[3])[0] != (*n[7])[0]);
+    };
+
+    if (std::any_of(elements.cbegin(), elements.cend(), is_voxel))
+    {
+        ERR("Input mesh needs to be voxel grid (i.e. equally sized axis "
+            "aligned hexahedra).");
+        return false;
     }
     return true;
-}
+}  // namespace
 }  // namespace
 namespace MeshToolsLib::MeshGenerator::AddFaultToVoxelGrid
 {
-- 
GitLab