From: Wolfgang Bangerth Date: Tue, 10 Oct 2023 14:29:53 +0000 (-0600) Subject: Make sure the conversion only works for 'const' types. X-Git-Tag: relicensing~414^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f7d7c8e0c487e023416fea8ff7f73042401c6b0;p=dealii.git Make sure the conversion only works for 'const' types. --- diff --git a/include/deal.II/base/array_view.h b/include/deal.II/base/array_view.h index 4cd48526f7..d158f86a7f 100644 --- a/include/deal.II/base/array_view.h +++ b/include/deal.II/base/array_view.h @@ -222,7 +222,7 @@ public: * This constructor allows for cases such as where one has a function * that takes an ArrayView object: * @code - * void f(const ArrayView &a); + * void f(const ArrayView &a); * @endcode * and then to call this function with a list of integers: * @code @@ -233,6 +233,12 @@ public: * f({}); * @encode * + * @note This constructor only works if the template type is `const` + * qualified. That is, you can initialize an `ArrayView` + * object from a `std::initializer_list`, but not an + * `ArrayView` object. This is because the elements of initializer + * lists are `const`. + * * @note `std::initializer_list` objects are temporary. They are constructed * where the compiler finds a brace-enclosed list, and so they only live * for at most the time it takes to execute the current statement. As a @@ -253,8 +259,9 @@ public: * f(a); * @endcode */ - ArrayView(const std::initializer_list> - &initializer_list); + ArrayView( + const std::initializer_list> &initializer_list) + DEAL_II_CXX20_REQUIRES(std::is_const_v); /** * Reinitialize a view. @@ -554,6 +561,7 @@ inline ArrayView::ArrayView( template inline ArrayView::ArrayView( const std::initializer_list> &initializer) + DEAL_II_CXX20_REQUIRES(std::is_const_v) : // use delegating constructor ArrayView((initializer.size() > 0 ? initializer.begin() : nullptr), initializer.size())