]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce ArrayView::cbegin and ArrayView::cend
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 24 Sep 2017 09:15:00 +0000 (11:15 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 24 Sep 2017 09:31:39 +0000 (11:31 +0200)
include/deal.II/base/array_view.h
tests/base/array_view_11.cc [new file with mode: 0644]
tests/base/array_view_11.output [new file with mode: 0644]

index 68f12651da16b942da529bbdeb2f63fb999a6d68..0cad1ad043250087dba306aefae49780ccd256c2 100644 (file)
@@ -167,22 +167,22 @@ public:
   /**
    * 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
@@ -297,7 +297,7 @@ ArrayView<ElementType>::size() const
 template <typename ElementType>
 inline
 typename ArrayView<ElementType>::iterator
-ArrayView<ElementType>::begin()
+ArrayView<ElementType>::begin() const
 {
   return starting_element;
 }
@@ -306,7 +306,7 @@ ArrayView<ElementType>::begin()
 template <typename ElementType>
 inline
 typename ArrayView<ElementType>::iterator
-ArrayView<ElementType>::end()
+ArrayView<ElementType>::end() const
 {
   return starting_element + n_elements;
 }
@@ -314,7 +314,7 @@ ArrayView<ElementType>::end()
 template <typename ElementType>
 inline
 typename ArrayView<ElementType>::const_iterator
-ArrayView<ElementType>::begin() const
+ArrayView<ElementType>::cbegin() const
 {
   return starting_element;
 }
@@ -323,7 +323,7 @@ ArrayView<ElementType>::begin() const
 template <typename ElementType>
 inline
 typename ArrayView<ElementType>::const_iterator
-ArrayView<ElementType>::end() const
+ArrayView<ElementType>::cend() const
 {
   return starting_element + n_elements;
 }
diff --git a/tests/base/array_view_11.cc b/tests/base/array_view_11.cc
new file mode 100644 (file)
index 0000000..651bdc6
--- /dev/null
@@ -0,0 +1,59 @@
+// ---------------------------------------------------------------------
+//
+// 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 ();
+}
diff --git a/tests/base/array_view_11.output b/tests/base/array_view_11.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

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.