Refactored code for positioning the focus and the start of iteration.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@327 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-03-05 22:16:12 +00:00
parent ddf619f934
commit 1dc51a1b13
6 changed files with 125 additions and 101 deletions
+36 -1
View File
@@ -6,7 +6,8 @@
namespace utils {
template <typename _InputIter, typename _Function>
_Function for_each_pre(_InputIter __first, _InputIter __last, _Function __f) {
_Function
for_each_pre(_InputIter __first, _InputIter __last, _Function __f) {
_InputIter __tmp;
while (__first != __last) {
@@ -18,6 +19,40 @@ _Function for_each_pre(_InputIter __first, _InputIter __last, _Function __f) {
return __f;
}
// Return a range with a distance of no more than __distance and
// between __first and __last, centered on __middle1.
template <typename _InputIter, typename _Distance>
std::pair<_InputIter, _InputIter>
iterate_both_distance(_InputIter __first, _InputIter __middle1, _InputIter __last, _Distance __distance) {
_InputIter __middle2 = __middle1;
do {
if (!__distance)
break;
if (__middle1 != __first) {
--__middle1;
--__distance;
} else if (__middle2 == __last) {
break;
}
if (!__distance)
break;
if (__middle2 != __last) {
++__middle2;
--__distance;
} else if (__middle1 == __first) {
break;
}
} while (true);
return std::make_pair(__middle1, __middle2);
}
}
#endif