From d5aa52c813fe35c5635d23fe3ed966d8ba3064eb Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 9 Feb 2021 18:22:51 -0700 Subject: [PATCH] Allow conversion from C-style array to ArrayView. --- include/deal.II/base/array_view.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/include/deal.II/base/array_view.h b/include/deal.II/base/array_view.h index f35415803a..087c8421c8 100644 --- a/include/deal.II/base/array_view.h +++ b/include/deal.II/base/array_view.h @@ -132,7 +132,8 @@ public: MemorySpaceType> &view); /** - * A constructor that automatically creates a view from a value_type object. + * A constructor that automatically creates a view from a single value_type + * object. The view so created then has length one. */ explicit ArrayView(value_type &element); @@ -169,6 +170,23 @@ public: */ ArrayView(std::vector::type> &vector); + /** + * A constructor that automatically creates a view for a given C-style array. + * This constructor can be used as follows: + * @code + * ArrayView + * get_data_table () + * { + * const int my_data[7] = { 1, 1, 2, 3, 5, 8, 13 }; + * return {my_data}; + * } + * @endcode + * The object so returned is then a view of the array, with the size 7 + * correctly deduced. + */ + template + ArrayView(value_type (&array)[N]); + /** * A constructor that automatically creates a view from a std::array object. * The view encompasses all elements of the given vector. @@ -472,6 +490,15 @@ inline ArrayView::ArrayView( +template +template +inline ArrayView::ArrayView( + ElementType (&array)[N]) + : ArrayView(&array[0], N) +{} + + + template template inline ArrayView::ArrayView( -- 2.39.5