mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-06 18:22:32 +00:00
da764db3b9
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@348 e378c898-3ddf-0310-93e7-cc216c733640
81 lines
2.0 KiB
C++
81 lines
2.0 KiB
C++
// rTorrent - BitTorrent client
|
|
// Copyright (C) 2005, Jari Sundell
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
//
|
|
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
|
//
|
|
// Skomakerveien 33
|
|
// 3185 Skoppum, NORWAY
|
|
|
|
#ifndef RTORRENT_UTILS_ALGORITHM_H
|
|
#define RTORRENT_UTILS_ALGORITHM_H
|
|
|
|
#include <algorithm>
|
|
|
|
namespace rak {
|
|
|
|
template <typename _InputIter, typename _Function>
|
|
_Function
|
|
for_each_pre(_InputIter __first, _InputIter __last, _Function __f) {
|
|
_InputIter __tmp;
|
|
|
|
while (__first != __last) {
|
|
__tmp = __first++;
|
|
|
|
__f(*__tmp);
|
|
}
|
|
|
|
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>
|
|
advance_bidirectional(_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
|