]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Also adjust value_type and array_type.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 16 Jan 2024 19:13:03 +0000 (12:13 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 18 Jan 2024 15:40:06 +0000 (08:40 -0700)
include/deal.II/base/tensor.h

index 5e91048882e59ffdc072bb73be64080084bed04d..b951af8709fa4dda21bd2cc3f2d37b95d6c51dfd 100644 (file)
@@ -548,16 +548,26 @@ public:
   /**
    * Type of objects encapsulated by this container and returned by
    * operator[](). This is a tensor of lower rank for a general tensor, and a
-   * scalar number type for Tensor<1,dim,Number>.
+   * scalar number type for rank-1 tensors.
    */
-  using value_type = typename Tensor<rank_ - 1, dim, Number>::tensor_type;
+  using value_type =
+    std::conditional_t<rank_ == 1, Number, Tensor<rank_ - 1, dim, Number>>;
 
   /**
    * Declare an array type which can be used to initialize an object of this
-   * type statically. For `dim == 0`, its size is 1. Otherwise, it is `dim`.
-   */
-  using array_type =
-    typename Tensor<rank_ - 1, dim, Number>::array_type[(dim != 0) ? dim : 1];
+   * type statically. For rank-1 tensors, this array is simply an array of
+   * length `dim` of scalars of type `Number`. For higher-rank tensors, it is an
+   * array of length `dim` of the `array_type` of the next lower-rank tensor.
+   *
+   * This class is occasionally instantiated for `dim == 0`. C++ does not allow
+   * the creation of zero-length arrays. As a consequence, if `dim==0`, then all
+   * arrays that *should* have length `dim` are instead declared as having
+   * length 1 to avoid compiler errors.
+   */
+  using array_type = std::conditional_t<
+    rank_ == 1,
+    Number[(dim != 0) ? dim : 1],
+    typename Tensor<rank_ - 1, dim, Number>::array_type[(dim != 0) ? dim : 1]>;
 
   /**
    * Constructor. Initialize all entries to zero.

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.