mini-llvm 0.1.0
Loading...
Searching...
No Matches
IndirectIterator.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <concepts>
6#include <iterator>
7#include <memory>
8#include <utility>
9
10namespace mini_llvm {
11
12// https://www.boost.org/doc/libs/1_86_0/libs/iterator/doc/indirect_iterator.html
13
14template <typename Iterator,
15 typename Value = typename std::pointer_traits<typename std::iterator_traits<Iterator>::value_type>::element_type>
17public:
18 using iterator_category = std::iterator_traits<Iterator>::iterator_category;
19 using value_type = Value;
20 using difference_type = std::iterator_traits<Iterator>::difference_type;
21 using pointer = Value *;
22 using reference = Value &;
23
24 IndirectIterator() = default;
25 explicit IndirectIterator(Iterator base) : base_(std::move(base)) {}
26
27 template <typename Iterator2, typename Value2>
28 requires std::convertible_to<Iterator2, Iterator>
29 IndirectIterator(const IndirectIterator<Iterator2, Value2> &other) : base_(other.base_) {}
30
31 Iterator base() const {
32 return base_;
33 }
34
36 return **base_;
37 }
38
40 return *base_[n];
41 }
42
44 return std::addressof(**base_);
45 }
46
48 ++base_;
49 return *this;
50 }
51
53 --base_;
54 return *this;
55 }
56
58 return IndirectIterator(base_++);
59 }
60
62 return IndirectIterator(base_--);
63 }
64
66 base_ += n;
67 return *this;
68 }
69
71 base_ -= n;
72 return *this;
73 }
74
75 bool operator==(const IndirectIterator &rhs) const {
76 return base_ == rhs.base_;
77 }
78
79 bool operator!=(const IndirectIterator &rhs) const {
80 return base_ != rhs.base_;
81 }
82
83 bool operator<(const IndirectIterator &rhs) const {
84 return base_ < rhs.base_;
85 }
86
87 bool operator>(const IndirectIterator &rhs) const {
88 return base_ > rhs.base_;
89 }
90
91 bool operator<=(const IndirectIterator &rhs) const {
92 return base_ <= rhs.base_;
93 }
94
95 bool operator>=(const IndirectIterator &rhs) const {
96 return base_ >= rhs.base_;
97 }
98
100 return base_ - rhs.base_;
101 }
102
104 return i += n;
105 }
106
108 return i -= n;
109 }
110
111private:
112 Iterator base_;
113
114 template <typename Iterator2, typename Value2>
115 friend class IndirectIterator;
116};
117
118} // namespace mini_llvm
reference operator[](difference_type n) const
Definition IndirectIterator.h:39
Instruction & reference
Definition IndirectIterator.h:22
difference_type operator-(const IndirectIterator &rhs) const
Definition IndirectIterator.h:99
friend class IndirectIterator
Definition IndirectIterator.h:115
friend IndirectIterator operator+(IndirectIterator i, difference_type n)
Definition IndirectIterator.h:103
bool operator>=(const IndirectIterator &rhs) const
Definition IndirectIterator.h:95
bool operator<=(const IndirectIterator &rhs) const
Definition IndirectIterator.h:91
IndirectIterator operator++(int)
Definition IndirectIterator.h:57
IndirectIterator operator--(int)
Definition IndirectIterator.h:61
Instruction * pointer
Definition IndirectIterator.h:21
IndirectIterator & operator++()
Definition IndirectIterator.h:47
IndirectIterator(const IndirectIterator< Iterator2, Value2 > &other)
Definition IndirectIterator.h:29
pointer operator->() const
Definition IndirectIterator.h:43
InstructionList::iterator base() const
Definition IndirectIterator.h:31
bool operator<(const IndirectIterator &rhs) const
Definition IndirectIterator.h:83
friend IndirectIterator operator-(IndirectIterator i, difference_type n)
Definition IndirectIterator.h:107
IndirectIterator & operator+=(difference_type n)
Definition IndirectIterator.h:65
IndirectIterator & operator--()
Definition IndirectIterator.h:52
reference operator*() const
Definition IndirectIterator.h:35
bool operator>(const IndirectIterator &rhs) const
Definition IndirectIterator.h:87
std::iterator_traits< InstructionList::iterator >::iterator_category iterator_category
Definition IndirectIterator.h:18
IndirectIterator & operator-=(difference_type n)
Definition IndirectIterator.h:70
std::iterator_traits< InstructionList::iterator >::difference_type difference_type
Definition IndirectIterator.h:20
Instruction value_type
Definition IndirectIterator.h:19
bool operator==(const IndirectIterator &rhs) const
Definition IndirectIterator.h:75
bool operator!=(const IndirectIterator &rhs) const
Definition IndirectIterator.h:79
IndirectIterator(Iterator base)
Definition IndirectIterator.h:25
Definition GraphColoringAllocator.h:13