]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Clean up cross_product_3d(). 18594/head
authorDavid Wells <drwells@email.unc.edu>
Fri, 27 Jun 2025 18:40:04 +0000 (14:40 -0400)
committerDavid Wells <drwells@email.unc.edu>
Fri, 27 Jun 2025 18:40:04 +0000 (14:40 -0400)
We can avoid the warning workaround by instead using if constexpr.

include/deal.II/base/tensor.h

index 3370bc30463cf81d2e3e80f0051826f45cb91a18..dd05d21e34b333381ca85c632313fa36c850d1fe 100644 (file)
@@ -2676,14 +2676,12 @@ constexpr inline DEAL_II_ALWAYS_INLINE
 
   Tensor<1, dim, typename ProductType<Number1, Number2>::type> result;
 
-  // avoid compiler warnings
-  constexpr int s0 = 0 % dim;
-  constexpr int s1 = 1 % dim;
-  constexpr int s2 = 2 % dim;
-
-  result[s0] = src1[s1] * src2[s2] - src1[s2] * src2[s1];
-  result[s1] = src1[s2] * src2[s0] - src1[s0] * src2[s2];
-  result[s2] = src1[s0] * src2[s1] - src1[s1] * src2[s0];
+  if constexpr (dim == 3)
+    {
+      result[0] = src1[1] * src2[2] - src1[2] * src2[1];
+      result[1] = src1[2] * src2[0] - src1[0] * src2[2];
+      result[2] = src1[0] * src2[1] - src1[1] * src2[0];
+    }
 
   return result;
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.