QWT
7.0.1
Loading...
Searching...
No Matches
src
qwt_algorithm.hpp
1
#ifndef QWT_ALGORITHM_HPP
2
#define QWT_ALGORITHM_HPP
3
#include <algorithm>
// std::find
4
#include <iterator>
// std::prev
5
99
template
<
typename
Iter >
100
Iter qwtSelectNextIterator(Iter begin, Iter end,
typename
std::iterator_traits< Iter >::value_type current,
bool
forward)
101
{
102
// 空范围直接返回 end
103
if
(begin == end) {
104
return
end;
105
}
106
107
// 查找当前元素在范围内的位置
108
Iter ite = std::find(begin, end, current);
109
110
// 若当前元素不在范围内,默认从第一个元素开始
111
if
(ite == end) {
112
ite = begin;
113
}
114
115
// 根据方向计算下一个迭代器
116
if
(forward) {
117
++ite;
118
if
(ite == end) {
// 到达末尾,循环到开头
119
ite = begin;
120
}
121
}
else
{
122
if
(ite != begin) {
// 未到开头,向前移动
123
--ite;
124
}
else
{
// 已在开头,循环到末尾
125
ite = std::prev(end);
126
}
127
}
128
129
return
ite;
130
}
131
132
#endif
// QWT_ALGORITHM_HPP
Generated by
1.9.8