]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a static_assert
authorMatthias Maier <tamiko@43-1.org>
Fri, 6 Sep 2019 00:18:13 +0000 (19:18 -0500)
committerMatthias Maier <tamiko@43-1.org>
Fri, 6 Sep 2019 00:41:30 +0000 (19:41 -0500)
include/deal.II/base/utilities.h

index 4c9ae69d84053fad60faf2535cd0e094cb746bc0..bdf6a13ee3e698be453b8e9105c04ff6fd6658fb 100644 (file)
@@ -1032,13 +1032,18 @@ namespace Utilities
   inline T
   fixed_power(const T x)
   {
+    static_assert(
+      !std::is_integral<T>::value || (N >= 0),
+      "The non-type template parameter N must be a non-negative integer for integral type T");
+
     if (N == 0)
       return T(1.);
     else if (N < 0)
       return T(1.) / fixed_power<-N>(x);
     else
       // Use exponentiation by squaring:
-      return ((N % 2 == 1) ? x * fixed_power<N / 2>(x * x) : fixed_power<N / 2>(x * x));
+      return ((N % 2 == 1) ? x * fixed_power<N / 2>(x * x) :
+                             fixed_power<N / 2>(x * x));
   }
 
 

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.