aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-05-20 17:55:35 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-05-20 17:55:35 +0000
commit847a48100b740be5f1432f8c98f87ac63c0432db (patch)
treeb38bddfdacd0608bd16bb28857a660a56e004dfa
parent437b443e10d98ae028df11a2ce5a3e52dfac8393 (diff)
downloadpaludis-847a48100b740be5f1432f8c98f87ac63c0432db.tar.gz
paludis-847a48100b740be5f1432f8c98f87ac63c0432db.tar.xz
Add an override of next() taking a distance to advance by.
-rw-r--r--paludis/util/iterator.hh13
-rw-r--r--paludis/util/iterator_TEST.cc6
2 files changed, 18 insertions, 1 deletions
diff --git a/paludis/util/iterator.hh b/paludis/util/iterator.hh
index 8da7f02..127fd48 100644
--- a/paludis/util/iterator.hh
+++ b/paludis/util/iterator.hh
@@ -48,6 +48,19 @@ namespace paludis
return ++result;
}
+ /**
+ * Return a new iterator advanced by a distance of n.
+ *
+ * \ingroup grpiterators
+ */
+ template <typename T_>
+ T_ next(const T_ & i, const int & n)
+ {
+ T_ result(i);
+ std::advance(result, n);
+ return result;
+ }
+
/**
* Return a new iterator pointing to the item before i.
*
diff --git a/paludis/util/iterator_TEST.cc b/paludis/util/iterator_TEST.cc
index a696e66..8a2cb76 100644
--- a/paludis/util/iterator_TEST.cc
+++ b/paludis/util/iterator_TEST.cc
@@ -227,10 +227,14 @@ namespace test_cases
std::vector<int> v;
v.push_back(1);
v.push_back(2);
+ v.push_back(3);
std::vector<int>::iterator iter(v.begin());
TEST_CHECK(*(next(iter)) == 2);
- TEST_CHECK(next(next(iter)) == v.end());
+ TEST_CHECK(next(next(next(iter))) == v.end());
+ TEST_CHECK(next(iter, 3) == v.end());
+ iter = next(iter);
+ TEST_CHECK(*(next(iter, 1)) == 3);
iter = next(iter);
TEST_CHECK(++iter == v.end());
}