-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapIterator.h
More file actions
71 lines (60 loc) · 1.93 KB
/
mapIterator.h
File metadata and controls
71 lines (60 loc) · 1.93 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include "Node.h"
#include <iterator>
#include <cassert>
#include "utils.h"
namespace ft {
template<class T>
class mapIterator {
public:
typedef std::bidirectional_iterator_tag iterator_category;
typedef T value_type;
typedef std::ptrdiff_t difference_type;
typedef value_type *pointer;
typedef value_type &reference;
typedef mapIterator<T> self_type;
typedef Node<typename remove_const<value_type>::type> node_type;
mapIterator(node_type *node = NULL) : _node(node) {};
private:
node_type *_node;
public:
template<class Some>
mapIterator(const mapIterator<Some> &it, typename enable_if<!is_const<Some>::value>::type* = 0) {
_node = it.GetNode();
}
mapIterator(const self_type &it) {
_node = it.GetNode();
}
node_type *GetNode() const {
return _node;
}
bool operator==(const mapIterator &rhs) const {
return _node == rhs._node;
}
bool operator!=(const mapIterator &rhs) const {
return !(rhs == *this);
}
self_type &operator++() {
_node = increment(_node);
return *this;
}
self_type operator++(int) {
self_type tmp = *this;
this->_node = increment(this->_node);
return tmp;
}
self_type &operator--() {
_node = decrement(_node);
return *this;
}
self_type operator--(int) {
self_type tmp = *this;
this->_node = decrement(this->_node);
return tmp;
}
reference operator*() { return const_cast<reference>(_node->val()); }
pointer operator->() { return &(_node->ref_val()); }
reference operator*() const { return const_cast<reference>(_node->val()); }
pointer operator->() const { return &(_node->ref_val()); }
};
}