NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
normal_iterator.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_ITERATOR_NORMAL_ITERATOR_HPP__
2#define NEFORCE_CORE_ITERATOR_NORMAL_ITERATOR_HPP__
3
10
12NEFORCE_BEGIN_NAMESPACE__
13
19
27template <typename Iterator>
29public:
30 using iterator_type = Iterator;
36
37private:
38 Iterator current_{};
39
40public:
44 constexpr normal_iterator() noexcept(is_nothrow_default_constructible_v<Iterator>) {}
45
50 explicit constexpr normal_iterator(const Iterator& iter) noexcept(is_nothrow_copy_constructible_v<Iterator>) :
51 current_(iter) {}
52
58 template <typename Iter, enable_if_t<is_convertible_v<Iter, Iterator>, int> = 0>
60 current_(other.base()) {}
61
66 constexpr reference operator*() const noexcept { return *current_; }
67
72 constexpr pointer operator->() const noexcept { return current_; }
73
78 constexpr normal_iterator& operator++() noexcept(noexcept(++current_)) {
79 ++current_;
80 return *this;
81 }
82
87 constexpr normal_iterator operator++(int) noexcept(noexcept(current_++)) { return normal_iterator(current_++); }
88
93 constexpr normal_iterator& operator--() noexcept(noexcept(--current_)) {
94 --current_;
95 return *this;
96 }
97
102 constexpr normal_iterator operator--(int) noexcept(noexcept(current_--)) { return normal_iterator(current_--); }
103
109 constexpr reference operator[](difference_type n) const noexcept { return current_[n]; }
110
116 constexpr normal_iterator& operator+=(difference_type n) noexcept(noexcept(current_ += n)) {
117 current_ += n;
118 return *this;
119 }
120
126 constexpr normal_iterator operator+(difference_type n) const noexcept(noexcept(current_ + n)) {
127 return normal_iterator(current_ + n);
128 }
129
135 constexpr normal_iterator& operator-=(difference_type n) noexcept(noexcept(current_ -= n)) {
136 current_ -= n;
137 return *this;
138 }
139
145 constexpr normal_iterator operator-(difference_type n) const noexcept(noexcept(current_ - n)) {
146 return normal_iterator(current_ - n);
147 }
148
153 constexpr const Iterator& base() const noexcept { return current_; }
154};
155
161template <typename LeftIter, typename RightIter>
162NEFORCE_NODISCARD constexpr bool operator==(const normal_iterator<LeftIter>& lhs,
163 const normal_iterator<RightIter>& rhs) noexcept {
164 return lhs.base() == rhs.base();
165}
166
171template <typename Iterator>
172NEFORCE_NODISCARD constexpr bool operator==(const normal_iterator<Iterator>& lhs,
173 const normal_iterator<Iterator>& rhs) noexcept {
174 return lhs.base() == rhs.base();
175}
176
182template <typename LeftIter, typename RightIter>
183NEFORCE_NODISCARD constexpr bool operator!=(const normal_iterator<LeftIter>& lhs,
184 const normal_iterator<RightIter>& rhs) noexcept {
185 return lhs.base() != rhs.base();
186}
187
192template <typename Iterator>
193NEFORCE_NODISCARD constexpr bool operator!=(const normal_iterator<Iterator>& lhs,
194 const normal_iterator<Iterator>& rhs) noexcept {
195 return lhs.base() != rhs.base();
196}
197
203template <typename LeftIter, typename RightIter>
204NEFORCE_NODISCARD constexpr bool operator<(const normal_iterator<LeftIter>& lhs,
205 const normal_iterator<RightIter>& rhs) noexcept {
206 return lhs.base() < rhs.base();
207}
208
213template <typename Iterator>
214NEFORCE_NODISCARD constexpr bool operator<(const normal_iterator<Iterator>& lhs,
215 const normal_iterator<Iterator>& rhs) noexcept {
216 return lhs.base() < rhs.base();
217}
218
224template <typename LeftIter, typename RightIter>
225NEFORCE_NODISCARD constexpr bool operator>(const normal_iterator<LeftIter>& lhs,
226 const normal_iterator<RightIter>& rhs) noexcept {
227 return lhs.base() > rhs.base();
228}
229
234template <typename Iterator>
235NEFORCE_NODISCARD constexpr bool operator>(const normal_iterator<Iterator>& lhs,
236 const normal_iterator<Iterator>& rhs) noexcept {
237 return lhs.base() > rhs.base();
238}
239
245template <typename LeftIter, typename RightIter>
246NEFORCE_NODISCARD constexpr bool operator<=(const normal_iterator<LeftIter>& lhs,
247 const normal_iterator<RightIter>& rhs) noexcept {
248 return lhs.base() <= rhs.base();
249}
250
255template <typename Iterator>
256NEFORCE_NODISCARD constexpr bool operator<=(const normal_iterator<Iterator>& lhs,
257 const normal_iterator<Iterator>& rhs) noexcept {
258 return lhs.base() <= rhs.base();
259}
260
266template <typename LeftIter, typename RightIter>
267NEFORCE_NODISCARD constexpr bool operator>=(const normal_iterator<LeftIter>& lhs,
268 const normal_iterator<RightIter>& rhs) noexcept {
269 return lhs.base() >= rhs.base();
270}
271
276template <typename Iterator>
277NEFORCE_NODISCARD constexpr bool operator>=(const normal_iterator<Iterator>& lhs,
278 const normal_iterator<Iterator>& rhs) noexcept {
279 return lhs.base() >= rhs.base();
280}
281
288template <typename LeftIter, typename RightIter>
289NEFORCE_NODISCARD constexpr auto operator-(const normal_iterator<LeftIter>& lhs,
290 const normal_iterator<RightIter>& rhs) noexcept
291 -> decltype(lhs.base() - rhs.base()) {
292 return lhs.base() - rhs.base();
293}
294
300template <typename Iterator>
301NEFORCE_NODISCARD constexpr typename normal_iterator<Iterator>::difference_type
303 return lhs.base() - rhs.base();
304}
305
313template <typename Iterator>
315 const normal_iterator<Iterator>& iter) noexcept {
316 return normal_iterator<Iterator>(iter.base() + n);
317}
318 // NormalIterators
320
321NEFORCE_END_NAMESPACE__
322#endif // NEFORCE_CORE_ITERATOR_NORMAL_ITERATOR_HPP__
标准迭代器适配器
constexpr normal_iterator & operator++() noexcept(noexcept(++current_))
前置自增操作符
constexpr normal_iterator(const normal_iterator< Iter > &other) noexcept(is_nothrow_copy_constructible_v< Iterator >)
从其他normal_iterator转换构造
constexpr normal_iterator operator+(difference_type n) const noexcept(noexcept(current_+n))
加法操作符
iter_difference_t< Iterator > difference_type
差值类型
iter_value_t< Iterator > value_type
元素值类型
constexpr const pointer & base() const noexcept
constexpr pointer operator->() const noexcept
成员访问操作符
constexpr reference operator[](difference_type n) const noexcept
下标访问操作符
constexpr normal_iterator() noexcept(is_nothrow_default_constructible_v< Iterator >)
默认构造函数
constexpr normal_iterator & operator--() noexcept(noexcept(--current_))
前置自减操作符
constexpr normal_iterator operator-(difference_type n) const noexcept(noexcept(current_ - n))
减法操作符
constexpr normal_iterator & operator-=(difference_type n) noexcept(noexcept(current_ -=n))
减法赋值操作符
constexpr normal_iterator(const Iterator &iter) noexcept(is_nothrow_copy_constructible_v< Iterator >)
从底层迭代器构造
iter_category_t< Iterator > iterator_category
迭代器类别
constexpr normal_iterator operator++(int) noexcept(noexcept(current_++))
后置自增操作符
constexpr reference operator*() const noexcept
解引用操作符
Iterator iterator_type
底层迭代器类型
iter_reference_t< Iterator > reference
引用类型
constexpr normal_iterator & operator+=(difference_type n) noexcept(noexcept(current_+=n))
加法赋值操作符
iter_pointer_t< Iterator > pointer
指针类型
constexpr normal_iterator operator--(int) noexcept(noexcept(current_--))
后置自减操作符
typename iterator_traits< Iterator >::reference iter_reference_t
获取迭代器的引用类型
typename iterator_traits< Iterator >::iterator_category iter_category_t
获取迭代器的类别标签
typename iterator_traits< Iterator >::value_type iter_value_t
获取迭代器的值类型
typename iterator_traits< Iterator >::difference_type iter_difference_t
获取迭代器的差值类型
typename iterator_traits< Iterator >::pointer iter_pointer_t
获取迭代器的指针类型
NEFORCE_NODISCARD constexpr bool operator<=(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
小于等于比较运算符
NEFORCE_NODISCARD constexpr bool operator<(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
小于比较运算符
NEFORCE_NODISCARD constexpr bool operator>(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
大于比较运算符
NEFORCE_NODISCARD constexpr bool operator!=(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
不等比较运算符
NEFORCE_NODISCARD constexpr auto operator-(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept -> decltype(lhs.base() - rhs.base())
减法运算符
NEFORCE_NODISCARD constexpr bool operator==(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
相等比较运算符
NEFORCE_NODISCARD constexpr normal_iterator< Iterator > operator+(iter_difference_t< normal_iterator< Iterator > > n, const normal_iterator< Iterator > &iter) noexcept
加法运算符
NEFORCE_NODISCARD constexpr bool operator>=(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
大于等于比较运算符
NEFORCE_INLINE17 constexpr bool is_nothrow_default_constructible_v
is_nothrow_default_constructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_copy_constructible_v
is_nothrow_copy_constructible的便捷变量模板
类型萃取