*/
ArrayView(std::vector<typename std::remove_cv<value_type>::type> &vector);
+ /**
+ * A constructor that automatically creates a view from a std::array object.
+ * The view encompasses all elements of the given vector.
+ *
+ * This implicit conversion constructor is particularly useful when calling
+ * a function that takes an ArrayView object as argument, and passing in
+ * a std::array.
+ */
+ template <std::size_t N>
+ ArrayView(
+ const std::array<typename std::remove_cv<value_type>::type, N> &vector);
+
+ /**
+ * A constructor that automatically creates a view from a std::array object.
+ * The view encompasses all elements of the given vector.
+ *
+ * This implicit conversion constructor is particularly useful when calling
+ * a function that takes an ArrayView object as argument, and passing in
+ * a std::array.
+ */
+ template <std::size_t N>
+ ArrayView(std::array<typename std::remove_cv<value_type>::type, N> &vector);
+
/**
* Reinitialize a view.
*
+template <typename ElementType, typename MemorySpaceType>
+template <std::size_t N>
+inline ArrayView<ElementType, MemorySpaceType>::ArrayView(
+ const std::array<typename std::remove_cv<value_type>::type, N> &vector)
+ : // use delegating constructor
+ ArrayView(vector.data(), vector.size())
+{
+ // the following static_assert is not strictly necessary because,
+ // if we got a const std::array reference argument but ElementType
+ // is not itself const, then the call to the forwarding constructor
+ // above will already have failed: vector.data() will have returned
+ // a const pointer, but we need a non-const pointer.
+ //
+ // nevertheless, leave the static_assert in since it provides a
+ // more descriptive error message that will simply come after the first
+ // error produced above
+ static_assert(std::is_const<value_type>::value == true,
+ "This constructor may only be called if the ArrayView "
+ "object has a const value_type. In other words, you can "
+ "only create an ArrayView to const values from a const "
+ "std::array.");
+}
+
+
+
+template <typename ElementType, typename MemorySpaceType>
+template <std::size_t N>
+inline ArrayView<ElementType, MemorySpaceType>::ArrayView(
+ std::array<typename std::remove_cv<value_type>::type, N> &vector)
+ : // use delegating constructor
+ ArrayView(vector.data(), vector.size())
+{}
+
+
+
template <typename ElementType, typename MemorySpaceType>
inline bool
ArrayView<ElementType, MemorySpaceType>::
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 - 2018 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// test for class ArrayView with std::array
+
+#include <deal.II/base/array_view.h>
+
+#include "../tests.h"
+
+
+void
+test()
+{
+ std::array<int, 10> v;
+
+ ArrayView<int> a(&v[4], 3); // writable view
+ a[2] = 42;
+
+ Assert(a[2] == 42, ExcInternalError());
+ Assert(v[6] == 42, ExcInternalError());
+
+ ArrayView<const int> a2(&v[4], 3); // readable view
+ Assert(a2[2] == 42, ExcInternalError());
+
+ ArrayView<const int> a3(a); // readable view, converted from 'a'
+ Assert(a3[2] == 42, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int
+main()
+{
+ initlog();
+
+ test();
+}