forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrap_iter.hpp
More file actions
51 lines (43 loc) · 1.51 KB
/
wrap_iter.hpp
File metadata and controls
51 lines (43 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef WRAP_ITER_HPP__
#define WRAP_ITER_HPP__
#include <iterator>
namespace iter {
template <typename Iterator>
class wrap_iter {
private:
Iterator iter;
typename std::iterator_traits<Iterator>::difference_type step;
public:
//using difference_type = typename std::iterator_traits<Iterator>::difference_type;
wrap_iter(const Iterator & iter,
typename std::iterator_traits<Iterator>::difference_type step) :
iter(iter),
step(step)
{ }
wrap_iter & operator++() {
std::advance(iter,step);
return *this;
}
bool operator!=(const wrap_iter & rhs) const {
return this->iter != rhs.iter;
}
auto operator*() const -> decltype(*iter)
{
return *iter;
}
};
template <typename Iterator>
wrap_iter<Iterator> make_wrap_iter(const Iterator & iter,
typename std::iterator_traits<Iterator>::difference_type step) {
return wrap_iter<Iterator>(iter,step);
}
}
namespace std {
template <typename Iterator>
struct iterator_traits<iter::wrap_iter<Iterator>> {
using difference_type = typename iterator_traits<Iterator>::difference_type;
using iterator_category = typename iterator_traits<Iterator>::iterator_category;
//should add the rest later for a more usable class
};
}
#endif //WRAP_ITER_HPP__