]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow conversion from C-style array to ArrayView.
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 10 Feb 2021 01:22:51 +0000 (18:22 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 10 Feb 2021 02:11:56 +0000 (19:11 -0700)
include/deal.II/base/array_view.h

index f35415803ab6249d8ae092d30479ac3feca87119..087c8421c82dc4fcade38b8e13f8c569d460cc46 100644 (file)
@@ -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<typename std::remove_cv<value_type>::type> &vector);
 
+  /**
+   * A constructor that automatically creates a view for a given C-style array.
+   * This constructor can be used as follows:
+   * @code
+   *   ArrayView<int>
+   *   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 <std::size_t N>
+  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<ElementType, MemorySpaceType>::ArrayView(
 
 
 
+template <typename ElementType, typename MemorySpaceType>
+template <std::size_t N>
+inline ArrayView<ElementType, MemorySpaceType>::ArrayView(
+  ElementType (&array)[N])
+  : ArrayView(&array[0], N)
+{}
+
+
+
 template <typename ElementType, typename MemorySpaceType>
 template <std::size_t N>
 inline ArrayView<ElementType, MemorySpaceType>::ArrayView(

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.