From 5f7d7c8e0c487e023416fea8ff7f73042401c6b0 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 10 Oct 2023 08:29:53 -0600 Subject: [PATCH] Make sure the conversion only works for 'const' types. --- include/deal.II/base/array_view.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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()) -- 2.39.5