return ArrayView<ElementType> (&vector[starting_index], size_of_view);
}
+#ifndef DOXYGEN
+namespace internal
+{
+ namespace ArrayViewHelper
+ {
+ template<class Iterator>
+ bool is_contiguous(const Iterator &first, const Iterator &last)
+ {
+ const auto n = std::distance(first, last);
+ for (typename std::decay<decltype(n)>::type i = 0; i < n; ++i)
+ if (*(std::next(first, i)) != *(std::next(std::addressof(*first), i)))
+ return false;
+ return true;
+ }
+ }
+}
+#endif
+
/**
* Create an ArrayView that takes a pair of iterators as arguments. The type
* <code>boost::container::small_vector</code> or <code>std::vector</code> and
* will not work correctly with, e.g.,
* <code>boost::container::stable_vector</code> or <code>std::deque</code>.
+ * In debug mode, we check that the provided iterators represent contiguous
+ * memory indeed.
*
* @relates ArrayView
*/
"The provided iterator should be a random access iterator.");
Assert(begin <= end,
ExcMessage("The beginning of the array view should be before the end."));
+ Assert(internal::ArrayViewHelper::is_contiguous(begin, end),
+ ExcMessage("The provided range isn't contiguous in memory!"));
// the reference type, not the value type, knows the constness of the iterator
return ArrayView<typename std::remove_reference
<typename std::iterator_traits<Iterator>::reference>::type>
// instantiate for integers:
template class Vector<int>;
template Vector<double> &Vector<double>::operator=<int> (const dealii::Vector<int> &);
+template bool Vector<int>::operator==<int> (dealii::Vector<int> const &) const;
template
void Vector<int>::reinit<double>(const Vector<double> &, const bool);
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// test for class ArrayView
+
+#include "../tests.h"
+
+#include <deal.II/base/array_view.h>
+
+template <typename T>
+void test (const T &t)
+{
+ try
+ {
+ make_array_view(std::begin(t), std::end(t));
+ }
+ catch (ExceptionBase &e)
+ {
+ deallog << e.get_exc_name() << std::endl;
+ }
+}
+
+int main()
+{
+ deal_II_exceptions::disable_abort_on_exception();
+ initlog();
+
+ auto d1 = std::deque<int>(2);
+ auto d2 = std::deque<int>(4000);
+ int c[] = { 1, 2, 3 };
+ auto a = std::array<int, 3> {{ 1, 2, 3 }};
+ auto s = std::string {"Hello world!"};
+ auto v = std::vector<int> { 1, 2, 3, };
+
+ deallog << "Testing std::deque<int>(2)" << std::endl;
+ test(d1);
+ deallog << "Testing std::deque<int>(4000)" << std::endl;
+ test(d2);
+ deallog << "Testing int c[3]{1,2,3}" << std::endl;
+ test(c);
+ deallog << "Testing std::array<int, 3> {{ 1,2,3}}" << std::endl;
+ test(a);
+ deallog << "Testing std::string {\"Hello world!\"}" << std::endl;
+ test(s);
+ deallog << "Testing std::vector<int>{1,2,3}" << std::endl;
+ test(v);
+}
--- /dev/null
+
+DEAL::Testing std::deque<int>(2)
+DEAL::Testing std::deque<int>(4000)
+DEAL::ExcMessage("The provided range isn't contiguous in memory!")
+DEAL::Testing int c[3]{1,2,3}
+DEAL::Testing std::array<int, 3> {{ 1,2,3}}
+DEAL::Testing std::string {"Hello world!"}
+DEAL::Testing std::vector<int>{1,2,3}