MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
normal_iterator.hpp
浏览该文件的文档.
1#ifndef MSTL_CORE_ITERATOR_NORMAL_ITERATOR_HPP__
2#define MSTL_CORE_ITERATOR_NORMAL_ITERATOR_HPP__
3
10
13
19
27template <typename Iterator>
29public:
30 using iterator_type = Iterator;
36
37private:
38 Iterator current_{};
39
40public:
44 constexpr normal_iterator()
45 noexcept(is_nothrow_default_constructible_v<Iterator>) {}
46
51 explicit constexpr normal_iterator(const Iterator& iter)
52 noexcept(is_nothrow_copy_constructible_v<Iterator>)
53 : current_(iter) {}
54
60 template <typename Iter, enable_if_t<is_convertible_v<Iter, Iterator>, int> = 0>
61 constexpr normal_iterator(const normal_iterator<Iter>& other)
62 noexcept(is_nothrow_copy_constructible_v<Iterator>)
63 : current_(other.base()) {}
64
69 constexpr reference operator *() const noexcept { return *current_; }
70
75 constexpr pointer operator ->() const noexcept { return current_; }
76
82 noexcept(noexcept(++current_)) {
83 ++current_;
84 return *this;
85 }
86
92 noexcept(noexcept(current_++)) {
93 return normal_iterator(current_++);
94 }
95
101 noexcept(noexcept(--current_)) {
102 --current_;
103 return *this;
104 }
105
111 noexcept(noexcept(current_--)) {
112 return normal_iterator(current_--);
113 }
114
120 constexpr reference operator [](difference_type n) const noexcept {
121 return current_[n];
122 }
123
130 noexcept(noexcept(current_ += n)) {
131 current_ += n;
132 return *this;
133 }
134
141 noexcept(noexcept(current_ + n)) {
142 return normal_iterator(current_ + n);
143 }
144
151 noexcept(noexcept(current_ -= n)) {
152 current_ -= n;
153 return *this;
154 }
155
162 noexcept(noexcept(current_ - n)) {
163 return normal_iterator(current_ - n);
164 }
165
170 constexpr const Iterator& base() const noexcept {
171 return current_;
172 }
173};
174
180template <typename LeftIter, typename RightIter>
181MSTL_NODISCARD constexpr bool operator ==(
182 const normal_iterator<LeftIter>& lhs,
183 const normal_iterator<RightIter>& rhs) noexcept {
184 return lhs.base() == rhs.base();
185}
186
191template <typename Iterator>
192MSTL_NODISCARD constexpr bool operator ==(
193 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>
204MSTL_NODISCARD constexpr bool operator !=(
205 const normal_iterator<LeftIter>& lhs,
206 const normal_iterator<RightIter>& rhs) noexcept {
207 return lhs.base() != rhs.base();
208}
209
214template <typename Iterator>
215MSTL_NODISCARD constexpr bool operator !=(
216 const normal_iterator<Iterator>& lhs,
217 const normal_iterator<Iterator>& rhs) noexcept {
218 return lhs.base() != rhs.base();
219}
220
226template <typename LeftIter, typename RightIter>
227MSTL_NODISCARD constexpr bool operator <(
228 const normal_iterator<LeftIter>& lhs,
229 const normal_iterator<RightIter>& rhs) noexcept {
230 return lhs.base() < rhs.base();
231}
232
237template <typename Iterator>
238MSTL_NODISCARD constexpr bool operator <(
239 const normal_iterator<Iterator>& lhs,
240 const normal_iterator<Iterator>& rhs) noexcept {
241 return lhs.base() < rhs.base();
242}
243
249template <typename LeftIter, typename RightIter>
250MSTL_NODISCARD constexpr bool operator >(
251 const normal_iterator<LeftIter>& lhs,
252 const normal_iterator<RightIter>& rhs) noexcept {
253 return lhs.base() > rhs.base();
254}
255
260template <typename Iterator>
261MSTL_NODISCARD constexpr bool operator >(
262 const normal_iterator<Iterator>& lhs,
263 const normal_iterator<Iterator>& rhs) noexcept {
264 return lhs.base() > rhs.base();
265}
266
272template <typename LeftIter, typename RightIter>
273MSTL_NODISCARD constexpr bool operator <=(
274 const normal_iterator<LeftIter>& lhs,
275 const normal_iterator<RightIter>& rhs) noexcept {
276 return lhs.base() <= rhs.base();
277}
278
283template <typename Iterator>
284MSTL_NODISCARD constexpr bool operator <=(
285 const normal_iterator<Iterator>& lhs,
286 const normal_iterator<Iterator>& rhs) noexcept {
287 return lhs.base() <= rhs.base();
288}
289
295template <typename LeftIter, typename RightIter>
296MSTL_NODISCARD constexpr bool operator >=(
297 const normal_iterator<LeftIter>& lhs,
298 const normal_iterator<RightIter>& rhs) noexcept {
299 return lhs.base() >= rhs.base();
300}
301
306template <typename Iterator>
307MSTL_NODISCARD constexpr bool operator >=(
308 const normal_iterator<Iterator>& lhs,
309 const normal_iterator<Iterator>& rhs) noexcept {
310 return lhs.base() >= rhs.base();
311}
312
319template <typename LeftIter, typename RightIter>
320MSTL_NODISCARD constexpr auto operator -(
321 const normal_iterator<LeftIter>& lhs,
322 const normal_iterator<RightIter>& rhs) noexcept
323 -> decltype(lhs.base() - rhs.base()) {
324 return lhs.base() - rhs.base();
325}
326
332template <typename Iterator>
333MSTL_NODISCARD constexpr typename normal_iterator<Iterator>::difference_type
335 const normal_iterator<Iterator>& rhs) noexcept {
336 return lhs.base() - rhs.base();
337}
338
346template <typename Iterator>
347MSTL_NODISCARD constexpr normal_iterator<Iterator>
349 const normal_iterator<Iterator>& iter) noexcept {
350 return normal_iterator<Iterator>(iter.base() + n);
351}
352 // NormalIterators
354
356#endif // MSTL_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 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
指针类型
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
获取迭代器的指针类型
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_NODISCARD constexpr normal_iterator< Iterator > operator+(iter_difference_t< normal_iterator< Iterator > > n, const normal_iterator< Iterator > &iter) noexcept
加法运算符
MSTL_NODISCARD constexpr bool operator!=(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
不等比较运算符
MSTL_NODISCARD constexpr bool operator==(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
相等比较运算符
MSTL_NODISCARD constexpr bool operator<=(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
小于等于比较运算符
MSTL_NODISCARD constexpr bool operator>=(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
大于等于比较运算符
MSTL_NODISCARD constexpr bool operator>(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
大于比较运算符
MSTL_NODISCARD constexpr auto operator-(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept -> decltype(lhs.base() - rhs.base())
减法运算符
MSTL_NODISCARD constexpr bool operator<(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
小于比较运算符
MSTL类型萃取