-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-26.h
46 lines (40 loc) · 1.69 KB
/
11-26.h
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
#ifndef KSTRIDE_ITER_HPP
#define KSTRIDE_ITER_HPP
#include <iterator>
template<class Iter_T, int Step_N>
class kstride_iter
{
public:
// public typedefs
typedef typename std::iterator_traits<Iter_T>::value_type value_type;
typedef typename std::iterator_traits<Iter_T>::reference reference;
typedef typename std::iterator_traits<Iter_T>::difference_type difference_type;
typedef typename std::iterator_traits<Iter_T>::pointer pointer;
typedef std::random_access_iterator_tag iterator_category;
typedef kstride_iter self;
// constructors
kstride_iter( ) : m(NULL) { }
kstride_iter(const self& x) : m(x.m) { }
explicit kstride_iter(Iter_T x) : m(x) { }
// operators
self& operator++( ) { m += Step_N; return *this; }
self operator++(int) { self tmp = *this; m += Step_N; return tmp; }
self& operator+=(difference_type x) { m += x * Step_N; return *this; }
self& operator--( ) { m -= Step_N; return *this; }
self operator--(int) { self tmp = *this; m -= Step_N; return tmp; }
self& operator-=(difference_type x) { m -= x * Step_N; return *this; }
reference operator[](difference_type n) { return m[n * Step_N]; }
reference operator*( ) { return *m; }
// friend operators
friend bool operator==(self x, self y) { return x.m == y.m; }
friend bool operator!=(self x, self y) { return x.m != y.m; }
friend bool operator<(self x, self y) { return x.m < y.m; }
friend difference_type operator-(self x, self y) {
return (x.m - y.m) / Step_N;
}
friend self operator+(self x, difference_type y) { return x += y * Step_N; }
friend self operator+(difference_type x, self y) { return y += x * Step_N; }
private:
Iter_T m;
};
#endif