From: Wolfgang Bangerth Date: Wed, 10 Feb 2021 01:22:51 +0000 (-0700) Subject: Allow conversion from C-style array to ArrayView. X-Git-Tag: v9.3.0-rc1~472^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5aa52c813fe35c5635d23fe3ed966d8ba3064eb;p=dealii.git Allow conversion from C-style array to ArrayView. --- 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(