]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Bugfix: Allow compilation in C++98 mode
authorMatthias Maier <tamiko@43-1.org>
Sat, 12 Sep 2015 23:47:11 +0000 (18:47 -0500)
committerMatthias Maier <tamiko@43-1.org>
Sat, 12 Sep 2015 23:58:16 +0000 (18:58 -0500)
The boost variant boost::enable_if_c cannot be used to prevent the compiler
from trying to form Tensor<rank, dim, Number> objects with negative rank -
this results in an infinite template substitution and subsequent failure.

But we can use the tensor class itself as cheap "enable_if" mechanism -
just specialize Tensor<-1, dim> and Tensor<-2, dim> such that they do not
contain the necessary overloads.

include/deal.II/base/tensor.h

index 706effbefc268c20e2b62bf00a481acf1df65aba..15d2754898b85ed2db93a55edc956122abcc6feb 100644 (file)
@@ -34,6 +34,19 @@ DEAL_II_NAMESPACE_OPEN
 template <int dim, typename Number> class Point;
 template <int rank_, int dim, typename Number = double> class Tensor;
 
+#ifndef DOXYGEN
+// Overload invalid tensor types of negative rank that come up during
+// overload resolution of operator* and related contraction variants.
+template <int dim, typename Number>
+class Tensor<-2, dim, Number>
+{
+};
+
+template <int dim, typename Number>
+class Tensor<-1, dim, Number>
+{
+};
+#endif /* DOXYGEN */
 
 
 /**
@@ -1502,10 +1515,7 @@ operator- (const Tensor<rank,dim,Number> &p, const Tensor<rank,dim,OtherNumber>
  * @relates ProductType
  */
 template <int rank_1, int rank_2, int dim,
-          typename Number, typename OtherNumber,
-          typename = typename std::enable_if<rank_1 != 0>::type,
-          typename = typename std::enable_if<rank_2 != 0>::type>
-
+          typename Number, typename OtherNumber>
 inline
 typename Tensor<rank_1 + rank_2 - 2, dim, typename ProductType<Number, OtherNumber>::type>::tensor_type
 operator * (const Tensor<rank_1, dim, Number> &src1,

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.