From: Daniel Arndt Date: Tue, 19 Nov 2019 23:49:12 +0000 (-0500) Subject: Avoid workaround for zero-dimensional C-style arrays X-Git-Tag: v9.2.0-rc1~862^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45c2c2f43a669fa4006489e2c5d5c3c0b40507b4;p=dealii.git Avoid workaround for zero-dimensional C-style arrays --- diff --git a/include/deal.II/base/tensor_product_polynomials.h b/include/deal.II/base/tensor_product_polynomials.h index 546904b53f..9423032102 100644 --- a/include/deal.II/base/tensor_product_polynomials.h +++ b/include/deal.II/base/tensor_product_polynomials.h @@ -231,10 +231,9 @@ protected: * dimensional polynomials for each space direction, given the index * i. */ - // fix to avoid compiler warnings about zero length arrays void - compute_index(const unsigned int i, - unsigned int (&indices)[(dim > 0 ? dim : 1)]) const; + compute_index(const unsigned int i, + std::array &indices) const; /** * TensorProductPolynomialsBubbles has a TensorProductPolynomials class @@ -410,8 +409,8 @@ private: * i. */ void - compute_index(const unsigned int i, - unsigned int (&indices)[(dim > 0 ? dim : 1)]) const; + compute_index(const unsigned int i, + std::array &indices) const; /** * Given the input to the constructor, compute n_pols. @@ -479,10 +478,10 @@ TensorProductPolynomials::compute_derivative( const unsigned int i, const Point & p) const { - unsigned int indices[dim]; + std::array indices; compute_index(i, indices); - double v[dim][5]; + std::array, dim> v; { std::vector tmp(5); for (unsigned int d = 0; d < dim; ++d) @@ -607,7 +606,7 @@ Tensor AnisotropicPolynomials::compute_derivative(const unsigned int i, const Point & p) const { - unsigned int indices[dim]; + std::array indices; compute_index(i, indices); std::vector> v(dim, std::vector(order + 1)); diff --git a/source/base/tensor_product_polynomials.cc b/source/base/tensor_product_polynomials.cc index d10d94b28c..521fd17323 100644 --- a/source/base/tensor_product_polynomials.cc +++ b/source/base/tensor_product_polynomials.cc @@ -38,35 +38,38 @@ namespace internal compute_tensor_index(const unsigned int, const unsigned int, const unsigned int, - unsigned int (&)[dim]) + std::array &) { Assert(false, ExcNotImplemented()); } + template <> inline void - compute_tensor_index(const unsigned int n, - const unsigned int, - const unsigned int, - unsigned int (&indices)[1]) + compute_tensor_index<1>(const unsigned int n, + const unsigned int, + const unsigned int, + std::array &indices) { indices[0] = n; } + template <> inline void - compute_tensor_index(const unsigned int n, - const unsigned int n_pols_0, - const unsigned int, - unsigned int (&indices)[2]) + compute_tensor_index<2>(const unsigned int n, + const unsigned int n_pols_0, + const unsigned int, + std::array &indices) { indices[0] = n % n_pols_0; indices[1] = n / n_pols_0; } + template <> inline void - compute_tensor_index(const unsigned int n, - const unsigned int n_pols_0, - const unsigned int n_pols_1, - unsigned int (&indices)[3]) + compute_tensor_index<3>(const unsigned int n, + const unsigned int n_pols_0, + const unsigned int n_pols_1, + std::array &indices) { indices[0] = n % n_pols_0; indices[1] = (n / n_pols_0) % n_pols_1; @@ -80,15 +83,15 @@ namespace internal template inline void TensorProductPolynomials::compute_index( - const unsigned int i, - unsigned int (&indices)[(dim > 0 ? dim : 1)]) const + const unsigned int i, + std::array &indices) const { Assert(i < Utilities::fixed_power(polynomials.size()), ExcInternalError()); - internal::compute_tensor_index(index_map[i], - polynomials.size(), - polynomials.size(), - indices); + internal::compute_tensor_index(index_map[i], + polynomials.size(), + polynomials.size(), + indices); } @@ -98,7 +101,7 @@ void TensorProductPolynomials::output_indices( std::ostream &out) const { - unsigned int ix[(dim > 0) ? dim : 1]; + std::array ix; for (unsigned int i = 0; i < this->n(); ++i) { compute_index(i, ix); @@ -146,7 +149,7 @@ TensorProductPolynomials::compute_value( { Assert(dim > 0, ExcNotImplemented()); - unsigned int indices[dim]; + std::array indices; compute_index(i, indices); double value = 1.; @@ -164,14 +167,14 @@ TensorProductPolynomials::compute_grad( const unsigned int i, const Point & p) const { - unsigned int indices[dim]; + std::array indices; compute_index(i, indices); // compute values and // uni-directional derivatives at // the given point in each // co-ordinate direction - double v[dim][2]; + std::array, dim> v; { std::vector tmp(2); for (unsigned int d = 0; d < dim; ++d) @@ -212,10 +215,10 @@ TensorProductPolynomials::compute_grad_grad( const unsigned int i, const Point & p) const { - unsigned int indices[(dim > 0) ? dim : 1]; + std::array indices; compute_index(i, indices); - double v[dim][3]; + std::array, dim> v; { std::vector tmp(3); for (unsigned int d = 0; d < dim; ++d) @@ -456,8 +459,8 @@ AnisotropicPolynomials::AnisotropicPolynomials( template void AnisotropicPolynomials::compute_index( - const unsigned int i, - unsigned int (&indices)[(dim > 0 ? dim : 1)]) const + const unsigned int i, + std::array &indices) const { #ifdef DEBUG unsigned int n_poly = 1; @@ -470,15 +473,15 @@ AnisotropicPolynomials::compute_index( { } else if (dim == 1) - internal::compute_tensor_index(i, - polynomials[0].size(), - 0 /*not used*/, - indices); + internal::compute_tensor_index(i, + polynomials[0].size(), + 0 /*not used*/, + indices); else - internal::compute_tensor_index(i, - polynomials[0].size(), - polynomials[1].size(), - indices); + internal::compute_tensor_index(i, + polynomials[0].size(), + polynomials[1].size(), + indices); } @@ -488,7 +491,7 @@ double AnisotropicPolynomials::compute_value(const unsigned int i, const Point & p) const { - unsigned int indices[(dim > 0) ? dim : 1]; + std::array indices; compute_index(i, indices); double value = 1.; @@ -504,7 +507,7 @@ Tensor<1, dim> AnisotropicPolynomials::compute_grad(const unsigned int i, const Point & p) const { - unsigned int indices[(dim > 0) ? dim : 1]; + std::array indices; compute_index(i, indices); // compute values and @@ -532,7 +535,7 @@ Tensor<2, dim> AnisotropicPolynomials::compute_grad_grad(const unsigned int i, const Point & p) const { - unsigned int indices[(dim > 0) ? dim : 1]; + std::array indices; compute_index(i, indices); std::vector> v(dim, std::vector(3)); @@ -627,7 +630,7 @@ AnisotropicPolynomials::evaluate( // one-dimensional indices of // this particular tensor // product polynomial - unsigned int indices[(dim > 0) ? dim : 1]; + std::array indices; compute_index(i, indices); if (update_values) diff --git a/source/base/tensor_product_polynomials_bubbles.cc b/source/base/tensor_product_polynomials_bubbles.cc index 3912dd03c5..59551672c7 100644 --- a/source/base/tensor_product_polynomials_bubbles.cc +++ b/source/base/tensor_product_polynomials_bubbles.cc @@ -30,7 +30,7 @@ template void TensorProductPolynomialsBubbles::output_indices(std::ostream &out) const { - unsigned int ix[dim]; + std::array ix; for (unsigned int i = 0; i < tensor_polys.n(); ++i) { tensor_polys.compute_index(i, ix); diff --git a/source/base/tensor_product_polynomials_const.cc b/source/base/tensor_product_polynomials_const.cc index 80efe0e013..f452a77d2f 100644 --- a/source/base/tensor_product_polynomials_const.cc +++ b/source/base/tensor_product_polynomials_const.cc @@ -30,7 +30,7 @@ template void TensorProductPolynomialsConst::output_indices(std::ostream &out) const { - unsigned int ix[dim]; + std::array ix; for (unsigned int i = 0; i < tensor_polys.n(); ++i) { tensor_polys.compute_index(i, ix);