From: Wolfgang Bangerth Date: Tue, 16 Jan 2024 19:13:03 +0000 (-0700) Subject: Also adjust value_type and array_type. X-Git-Tag: relicensing~145^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18309ab2c61c1db147ca25ac6f9950cb3011a730;p=dealii.git Also adjust value_type and array_type. --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 5e91048882..b951af8709 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -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::tensor_type; + using value_type = + std::conditional_t>; /** * 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::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::array_type[(dim != 0) ? dim : 1]>; /** * Constructor. Initialize all entries to zero.