From: Daniel Arndt Date: Sun, 24 Sep 2017 09:15:00 +0000 (+0200) Subject: Introduce ArrayView::cbegin and ArrayView::cend X-Git-Tag: v9.0.0-rc1~1038^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2ce12cf85923f896fb0239f254010e492611b60;p=dealii.git Introduce ArrayView::cbegin and ArrayView::cend --- diff --git a/include/deal.II/base/array_view.h b/include/deal.II/base/array_view.h index 68f12651da..0cad1ad043 100644 --- a/include/deal.II/base/array_view.h +++ b/include/deal.II/base/array_view.h @@ -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::size() const template inline typename ArrayView::iterator -ArrayView::begin() +ArrayView::begin() const { return starting_element; } @@ -306,7 +306,7 @@ ArrayView::begin() template inline typename ArrayView::iterator -ArrayView::end() +ArrayView::end() const { return starting_element + n_elements; } @@ -314,7 +314,7 @@ ArrayView::end() template inline typename ArrayView::const_iterator -ArrayView::begin() const +ArrayView::cbegin() const { return starting_element; } @@ -323,7 +323,7 @@ ArrayView::begin() const template inline typename ArrayView::const_iterator -ArrayView::end() const +ArrayView::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 index 0000000000..651bdc65aa --- /dev/null +++ b/tests/base/array_view_11.cc @@ -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 + + +void test () +{ + { + std::vector arr = {0,1,2,3,4,5,6,7,8,9}; + ArrayView 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 arr = {0,1,2,3,4,5,6,7,8,9}; + const ArrayView 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 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/base/array_view_11.output @@ -0,0 +1,2 @@ + +DEAL::OK