/**
* Return an iterator pointing to the beginning of the array view.
*/
- iterator begin();
+ iterator begin() const;
/**
* Return an iterator pointing to one past the end of the array view.
*/
- iterator end();
+ iterator end() const;
/**
* Return a constant iterator pointing to the beginning of the array view.
*/
- const_iterator begin() const;
+ const_iterator cbegin() const;
/**
* Return a constant iterator pointing to one past the end of the array view.
*/
- const_iterator end() const;
+ const_iterator cend() const;
/**
* Return a reference to the $i$th element of the range represented by the
template <typename ElementType>
inline
typename ArrayView<ElementType>::iterator
-ArrayView<ElementType>::begin()
+ArrayView<ElementType>::begin() const
{
return starting_element;
}
template <typename ElementType>
inline
typename ArrayView<ElementType>::iterator
-ArrayView<ElementType>::end()
+ArrayView<ElementType>::end() const
{
return starting_element + n_elements;
}
template <typename ElementType>
inline
typename ArrayView<ElementType>::const_iterator
-ArrayView<ElementType>::begin() const
+ArrayView<ElementType>::cbegin() const
{
return starting_element;
}
template <typename ElementType>
inline
typename ArrayView<ElementType>::const_iterator
-ArrayView<ElementType>::end() const
+ArrayView<ElementType>::cend() const
{
return starting_element + n_elements;
}
--- /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>
+
+
+void test ()
+{
+ {
+ std::vector<int> arr = {0,1,2,3,4,5,6,7,8,9};
+ ArrayView<int> view (arr); // writable view
+ for (auto &el: view)
+ ++el;
+
+ int i=0;
+ for (auto &&it = arr.cbegin(); it != arr.cend(); ++it, ++i)
+ AssertThrow (*it == i+1, ExcInternalError());
+ }
+
+ {
+ std::vector<int> arr = {0,1,2,3,4,5,6,7,8,9};
+ const ArrayView<int> view (arr); // writable view
+ for (auto &el: view)
+ ++el;
+
+ int i=0;
+ for (auto &&it = arr.cbegin(); it != arr.cend(); ++it, ++i)
+ AssertThrow (*it == i+1, ExcInternalError());
+ }
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+
+int main()
+{
+ initlog();
+
+ test ();
+}