summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/iterator/test/advance_test.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/iterator/test/advance_test.cpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/iterator/test/advance_test.cpp')
-rw-r--r--src/boost/libs/iterator/test/advance_test.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/boost/libs/iterator/test/advance_test.cpp b/src/boost/libs/iterator/test/advance_test.cpp
new file mode 100644
index 00000000..85cd4ac6
--- /dev/null
+++ b/src/boost/libs/iterator/test/advance_test.cpp
@@ -0,0 +1,91 @@
+// Copyright (C) 2017 Michel Morin.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <vector>
+#include <list>
+#include <boost/container/slist.hpp>
+#include <boost/core/lightweight_test.hpp>
+#include <boost/iterator/advance.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+
+int twice(int x) { return x + x; }
+
+template <typename Iterator>
+void test_advance(Iterator it_from, Iterator it_to, int n)
+{
+ boost::advance(it_from, n);
+ BOOST_TEST(it_from == it_to);
+}
+
+int main()
+{
+ int array[3] = {1, 2, 3};
+ int* ptr1 = array;
+ int* ptr2 = array + 3;
+
+ {
+ test_advance(ptr1, ptr2, 3);
+ test_advance(ptr2, ptr1, -3);
+
+ test_advance(
+ boost::make_transform_iterator(ptr1, twice)
+ , boost::make_transform_iterator(ptr2, twice)
+ , 3
+ );
+ test_advance(
+ boost::make_transform_iterator(ptr2, twice)
+ , boost::make_transform_iterator(ptr1, twice)
+ , -3
+ );
+ }
+
+ {
+ std::vector<int> ints(ptr1, ptr2);
+ test_advance(ints.begin(), ints.end(), 3);
+ test_advance(ints.end(), ints.begin(), -3);
+
+ test_advance(
+ boost::make_transform_iterator(ints.begin(), twice)
+ , boost::make_transform_iterator(ints.end(), twice)
+ , 3
+ );
+ test_advance(
+ boost::make_transform_iterator(ints.end(), twice)
+ , boost::make_transform_iterator(ints.begin(), twice)
+ , -3
+ );
+ }
+
+ {
+ std::list<int> ints(ptr1, ptr2);
+ test_advance(ints.begin(), ints.end(), 3);
+ test_advance(ints.end(), ints.begin(), -3);
+
+ test_advance(
+ boost::make_transform_iterator(ints.begin(), twice)
+ , boost::make_transform_iterator(ints.end(), twice)
+ , 3
+ );
+ test_advance(
+ boost::make_transform_iterator(ints.end(), twice)
+ , boost::make_transform_iterator(ints.begin(), twice)
+ , -3
+ );
+ }
+
+ {
+ boost::container::slist<int> ints(ptr1, ptr2);
+ test_advance(ints.begin(), ints.end(), 3);
+
+ test_advance(
+ boost::make_transform_iterator(ints.begin(), twice)
+ , boost::make_transform_iterator(ints.end(), twice)
+ , 3
+ );
+ }
+
+ return boost::report_errors();
+}