Skip to content

Commit f984e8a

Browse files
committed
1 parent 0c8dfc8 commit f984e8a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

libc/src/__support/CPP/iterator.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ namespace cpp {
2020
template <typename T> struct iterator_traits;
2121
template <typename T> struct iterator_traits<T *> {
2222
using reference = T &;
23+
using value_type = T;
2324
};
2425

2526
template <typename Iter> class reverse_iterator {
2627
Iter current;
2728

2829
public:
2930
using reference = typename iterator_traits<Iter>::reference;
31+
using value_type = typename iterator_traits<Iter>::value_type;
3032

3133
LIBC_INLINE reverse_iterator() : current() {}
3234
LIBC_INLINE constexpr explicit reverse_iterator(Iter it) : current(it) {}
@@ -38,6 +40,38 @@ template <typename Iter> class reverse_iterator {
3840
LIBC_INLINE constexpr explicit reverse_iterator(const Other &it)
3941
: current(it) {}
4042

43+
LIBC_INLINE friend constexpr bool operator==(const reverse_iterator &lhs,
44+
const reverse_iterator &rhs) {
45+
return lhs.base() == rhs.base();
46+
}
47+
48+
LIBC_INLINE friend constexpr bool operator!=(const reverse_iterator &lhs,
49+
const reverse_iterator &rhs) {
50+
return lhs.base() != rhs.base();
51+
}
52+
53+
LIBC_INLINE friend constexpr bool operator<(const reverse_iterator &lhs,
54+
const reverse_iterator &rhs) {
55+
return lhs.base() < rhs.base();
56+
}
57+
58+
LIBC_INLINE friend constexpr bool operator<=(const reverse_iterator &lhs,
59+
const reverse_iterator &rhs) {
60+
return lhs.base() <= rhs.base();
61+
}
62+
63+
LIBC_INLINE friend constexpr bool operator>(const reverse_iterator &lhs,
64+
const reverse_iterator &rhs) {
65+
return lhs.base() > rhs.base();
66+
}
67+
68+
LIBC_INLINE friend constexpr bool operator>=(const reverse_iterator &lhs,
69+
const reverse_iterator &rhs) {
70+
return lhs.base() >= rhs.base();
71+
}
72+
73+
LIBC_INLINE constexpr iterator_type base() const { current; }
74+
4175
LIBC_INLINE constexpr reference operator*() const {
4276
Iter tmp = current;
4377
return *--tmp;

0 commit comments

Comments
 (0)