forked from xcore/tool_axe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AccessSecondIterator.h
45 lines (41 loc) · 1.23 KB
/
AccessSecondIterator.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
// Copyright (c) 2011, Richard Osborne, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>
#ifndef _AccessSecondIterator_h_
#define _AccessSecondIterator_h_
#include <iterator>
template <typename Iterator>
class AccessSecondIterator :
public std::iterator<
std::forward_iterator_tag,
typename std::iterator_traits<Iterator>::value_type::second_type> {
Iterator it;
public:
AccessSecondIterator() {}
AccessSecondIterator(Iterator i) : it(i) {}
AccessSecondIterator &operator++() {
++it;
return *this;
}
AccessSecondIterator operator++(int) {
AccessSecondIterator tmp(*this);
operator++();
return tmp;
}
const typename std::iterator_traits<Iterator>::value_type::second_type &
operator*() const {
return it->second;
}
const typename std::iterator_traits<Iterator>::value_type::second_type *
operator->() const {
return &**this;
}
bool operator==(const AccessSecondIterator &other) {
return it == other.it;
}
bool operator!=(const AccessSecondIterator &other) {
return !(*this == other);
}
};
#endif // _AccessSecondIterator_h_