From: Wolfgang Bangerth Date: Mon, 9 Oct 2023 23:11:28 +0000 (-0600) Subject: Make sure ArrayView of an empty array really is a nullptr. X-Git-Tag: relicensing~418^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4290efa0b128d6fa2ba2491fb0d476104c319e05;p=dealii.git Make sure ArrayView of an empty array really is a nullptr. --- diff --git a/include/deal.II/base/array_view.h b/include/deal.II/base/array_view.h index 684789e32e..a500702329 100644 --- a/include/deal.II/base/array_view.h +++ b/include/deal.II/base/array_view.h @@ -110,7 +110,10 @@ public: * Constructor. * * @param[in] starting_element A pointer to the first element of the array - * this object should represent. + * this object should represent. The value of this argument is only evaluated + * if `n_elements` is larger than zero. Otherwise, the value of this + * argument is ignored as if the ArrayView object used a `nullptr` + * to point to the first element of the array. * @param[in] n_elements The length (in elements) of the chunk of memory * this object should represent. * @@ -400,7 +403,7 @@ template inline ArrayView::ArrayView( value_type *starting_element, const std::size_t n_elements) - : starting_element(starting_element) + : starting_element(n_elements > 0 ? starting_element : nullptr) , n_elements(n_elements) {} @@ -411,8 +414,11 @@ inline void ArrayView::reinit(value_type *starting_element, const std::size_t n_elements) { - this->starting_element = starting_element; - this->n_elements = n_elements; + if (n_elements > 0) + this->starting_element = starting_element; + else + this->starting_element = nullptr; + this->n_elements = n_elements; }