Debian Codegraph @

libcxx/include/__cxx03/__iterator/wrap_iter.h

raw
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef _LIBCPP___CXX03___ITERATOR_WRAP_ITER_H
11 #define _LIBCPP___CXX03___ITERATOR_WRAP_ITER_H
12
13 #include <__cxx03/__config>
14 #include <__cxx03/__iterator/iterator_traits.h>
15 #include <__cxx03/__memory/addressof.h>
16 #include <__cxx03/__memory/pointer_traits.h>
17 #include <__cxx03/__type_traits/enable_if.h>
18 #include <__cxx03/__type_traits/is_convertible.h>
19 #include <__cxx03/cstddef>
20
21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22 # pragma GCC system_header
23 #endif
24
25 _LIBCPP_BEGIN_NAMESPACE_STD
26
27 template <class _Iter>
28 class __wrap_iter {
29 public:
30 typedef _Iter iterator_type;
31 typedef typename iterator_traits<iterator_type>::value_type value_type;
32 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
33 typedef typename iterator_traits<iterator_type>::pointer pointer;
34 typedef typename iterator_traits<iterator_type>::reference reference;
35 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
36
37 private:
38 iterator_type __i_;
39
40 public:
41 _LIBCPP_HIDE_FROM_ABI __wrap_iter() _NOEXCEPT : __i_() {}
42 template <class _Up, __enable_if_t<is_convertible<_Up, iterator_type>::value, int> = 0>
43 _LIBCPP_HIDE_FROM_ABI __wrap_iter(const __wrap_iter<_Up>& __u) _NOEXCEPT : __i_(__u.base()) {}
44 _LIBCPP_HIDE_FROM_ABI reference operator*() const _NOEXCEPT { return *__i_; }
45 _LIBCPP_HIDE_FROM_ABI pointer operator->() const _NOEXCEPT { return std::__to_address(__i_); }
46 _LIBCPP_HIDE_FROM_ABI __wrap_iter& operator++() _NOEXCEPT {
47 ++__i_;
48 return *this;
49 }
50 _LIBCPP_HIDE_FROM_ABI __wrap_iter operator++(int) _NOEXCEPT {
51 __wrap_iter __tmp(*this);
52 ++(*this);
53 return __tmp;
54 }
55
56 _LIBCPP_HIDE_FROM_ABI __wrap_iter& operator--() _NOEXCEPT {
57 --__i_;
58 return *this;
59 }
60 _LIBCPP_HIDE_FROM_ABI __wrap_iter operator--(int) _NOEXCEPT {
61 __wrap_iter __tmp(*this);
62 --(*this);
63 return __tmp;
64 }
65 _LIBCPP_HIDE_FROM_ABI __wrap_iter operator+(difference_type __n) const _NOEXCEPT {
66 __wrap_iter __w(*this);
67 __w += __n;
68 return __w;
69 }
70 _LIBCPP_HIDE_FROM_ABI __wrap_iter& operator+=(difference_type __n) _NOEXCEPT {
71 __i_ += __n;
72 return *this;
73 }
74 _LIBCPP_HIDE_FROM_ABI __wrap_iter operator-(difference_type __n) const _NOEXCEPT { return *this + (-__n); }
75 _LIBCPP_HIDE_FROM_ABI __wrap_iter& operator-=(difference_type __n) _NOEXCEPT {
76 *this += -__n;
77 return *this;
78 }
79 _LIBCPP_HIDE_FROM_ABI reference operator[](difference_type __n) const _NOEXCEPT { return __i_[__n]; }
80
81 _LIBCPP_HIDE_FROM_ABI iterator_type base() const _NOEXCEPT { return __i_; }
82
83 private:
84 _LIBCPP_HIDE_FROM_ABI explicit __wrap_iter(iterator_type __x) _NOEXCEPT : __i_(__x) {}
85
86 template <class _Up>
87 friend class __wrap_iter;
88 template <class _CharT, class _Traits, class _Alloc>
89 friend class basic_string;
90 template <class _CharT, class _Traits>
91 friend class basic_string_view;
92 template <class _Tp, class _Alloc>
93 friend class _LIBCPP_TEMPLATE_VIS vector;
94 template <class _Tp, size_t>
95 friend class _LIBCPP_TEMPLATE_VIS span;
96 template <class _Tp, size_t _Size>
97 friend struct array;
98 };
99
100 template <class _Iter1>
101 _LIBCPP_HIDE_FROM_ABI bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
102 return __x.base() == __y.base();
103 }
104
105 template <class _Iter1, class _Iter2>
106 _LIBCPP_HIDE_FROM_ABI bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
107 return __x.base() == __y.base();
108 }
109
110 template <class _Iter1>
111 _LIBCPP_HIDE_FROM_ABI bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
112 return __x.base() < __y.base();
113 }
114
115 template <class _Iter1, class _Iter2>
116 _LIBCPP_HIDE_FROM_ABI bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
117 return __x.base() < __y.base();
118 }
119
120 template <class _Iter1>
121 _LIBCPP_HIDE_FROM_ABI bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
122 return !(__x == __y);
123 }
124
125 template <class _Iter1, class _Iter2>
126 _LIBCPP_HIDE_FROM_ABI bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
127 return !(__x == __y);
128 }
129
130 // TODO(mordante) disable these overloads in the LLVM 20 release.
131 template <class _Iter1>
132 _LIBCPP_HIDE_FROM_ABI bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
133 return __y < __x;
134 }
135
136 template <class _Iter1, class _Iter2>
137 _LIBCPP_HIDE_FROM_ABI bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
138 return __y < __x;
139 }
140
141 template <class _Iter1>
142 _LIBCPP_HIDE_FROM_ABI bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
143 return !(__x < __y);
144 }
145
146 template <class _Iter1, class _Iter2>
147 _LIBCPP_HIDE_FROM_ABI bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
148 return !(__x < __y);
149 }
150
151 template <class _Iter1>
152 _LIBCPP_HIDE_FROM_ABI bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
153 return !(__y < __x);
154 }
155
156 template <class _Iter1, class _Iter2>
157 _LIBCPP_HIDE_FROM_ABI bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
158 return !(__y < __x);
159 }
160
161 template <class _Iter1, class _Iter2>
162 _LIBCPP_HIDE_FROM_ABI typename __wrap_iter<_Iter1>::difference_type
163 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
164 return __x.base() - __y.base();
165 }
166
167 template <class _Iter1>
168 _LIBCPP_HIDE_FROM_ABI __wrap_iter<_Iter1>
169 operator+(typename __wrap_iter<_Iter1>::difference_type __n, __wrap_iter<_Iter1> __x) _NOEXCEPT {
170 __x += __n;
171 return __x;
172 }
173
174 template <class _It>
175 struct __libcpp_is_contiguous_iterator<__wrap_iter<_It> > : true_type {};
176
177 template <class _It>
178 struct _LIBCPP_TEMPLATE_VIS pointer_traits<__wrap_iter<_It> > {
179 typedef __wrap_iter<_It> pointer;
180 typedef typename pointer_traits<_It>::element_type element_type;
181 typedef typename pointer_traits<_It>::difference_type difference_type;
182
183 _LIBCPP_HIDE_FROM_ABI static element_type* to_address(pointer __w) _NOEXCEPT { return std::__to_address(__w.base()); }
184 };
185
186 _LIBCPP_END_NAMESPACE_STD
187
188 #endif // _LIBCPP___CXX03___ITERATOR_WRAP_ITER_H