]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify template_power function for the compiler.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 15 Mar 2006 16:39:54 +0000 (16:39 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 15 Mar 2006 16:39:54 +0000 (16:39 +0000)
git-svn-id: https://svn.dealii.org/trunk@12597 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/data_out_base.cc

index 454da55a356e277d45ec97ac6dd0bd5817083316..4912097369d1c8ca8b453e1840a0a278c94a4da6 100644 (file)
@@ -127,16 +127,25 @@ compute_node(
 // Compute n^dim, where dim is a template parameter
 template<int dim>
 inline
-unsigned int template_power(const unsigned int n)
+unsigned int template_power (const unsigned int n)
 {
   Assert (dim>0, ExcNotImplemented());
-                                  // The argument already contains the first power.
-  if (dim==1) return n;
-                                  // Else, we must compute.
-  unsigned int result = n;  
-  for (unsigned int d=1;d<dim;++d)
-    result *= n;
-  return result;
+  switch (dim)
+    {
+      case 1:
+           return n;
+      case 2:
+           return n*n;
+      case 3:
+           return n*n*n;
+      case 4:
+           return n*n*n*n;
+      default:
+           unsigned int result = n;  
+           for (unsigned int d=1;d<dim;++d)
+             result *= n;
+           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.