2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___ITERATOR_WRAP_ITER_H
11 #define _LIBCPP___ITERATOR_WRAP_ITER_H
14 #include <__iterator/iterator_traits.h>
15 #include <__memory/addressof.h>
16 #include <__memory/pointer_traits.h>
17 #include <__type_traits/enable_if.h>
18 #include <__type_traits/is_convertible.h>
21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22 # pragma GCC system_header
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 template <class _Iter
>
31 typedef _Iter iterator_type
;
32 typedef typename iterator_traits
<iterator_type
>::value_type value_type
;
33 typedef typename iterator_traits
<iterator_type
>::difference_type difference_type
;
34 typedef typename iterator_traits
<iterator_type
>::pointer pointer
;
35 typedef typename iterator_traits
<iterator_type
>::reference reference
;
36 typedef typename iterator_traits
<iterator_type
>::iterator_category iterator_category
;
37 #if _LIBCPP_STD_VER >= 20
38 typedef contiguous_iterator_tag iterator_concept
;
44 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
__wrap_iter() _NOEXCEPT
48 template <class _Up
, __enable_if_t
<is_convertible
<_Up
, iterator_type
>::value
, int> = 0>
49 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
__wrap_iter(const __wrap_iter
<_Up
>& __u
) _NOEXCEPT
53 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference
operator*() const _NOEXCEPT
57 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pointer
operator->() const _NOEXCEPT
59 return _VSTD::__to_address(__i_
);
61 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
& operator++() _NOEXCEPT
66 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
operator++(int) _NOEXCEPT
67 {__wrap_iter
__tmp(*this); ++(*this); return __tmp
;}
69 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
& operator--() _NOEXCEPT
74 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
operator--(int) _NOEXCEPT
75 {__wrap_iter
__tmp(*this); --(*this); return __tmp
;}
76 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
operator+ (difference_type __n
) const _NOEXCEPT
77 {__wrap_iter
__w(*this); __w
+= __n
; return __w
;}
78 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
& operator+=(difference_type __n
) _NOEXCEPT
83 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
operator- (difference_type __n
) const _NOEXCEPT
84 {return *this + (-__n
);}
85 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter
& operator-=(difference_type __n
) _NOEXCEPT
86 {*this += -__n
; return *this;}
87 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference
operator[](difference_type __n
) const _NOEXCEPT
92 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 iterator_type
base() const _NOEXCEPT
{return __i_
;}
95 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
96 explicit __wrap_iter(iterator_type __x
) _NOEXCEPT
: __i_(__x
)
100 template <class _Up
> friend class __wrap_iter
;
101 template <class _CharT
, class _Traits
, class _Alloc
> friend class basic_string
;
102 template <class _Tp
, class _Alloc
> friend class _LIBCPP_TEMPLATE_VIS vector
;
103 template <class _Tp
, size_t> friend class _LIBCPP_TEMPLATE_VIS span
;
106 template <class _Iter1
>
107 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
108 bool operator==(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter1
>& __y
) _NOEXCEPT
110 return __x
.base() == __y
.base();
113 template <class _Iter1
, class _Iter2
>
114 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
115 bool operator==(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter2
>& __y
) _NOEXCEPT
117 return __x
.base() == __y
.base();
120 template <class _Iter1
>
121 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
122 bool operator<(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter1
>& __y
) _NOEXCEPT
124 return __x
.base() < __y
.base();
127 template <class _Iter1
, class _Iter2
>
128 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
129 bool operator<(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter2
>& __y
) _NOEXCEPT
131 return __x
.base() < __y
.base();
134 template <class _Iter1
>
135 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
136 bool operator!=(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter1
>& __y
) _NOEXCEPT
138 return !(__x
== __y
);
141 template <class _Iter1
, class _Iter2
>
142 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
143 bool operator!=(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter2
>& __y
) _NOEXCEPT
145 return !(__x
== __y
);
148 template <class _Iter1
>
149 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
150 bool operator>(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter1
>& __y
) _NOEXCEPT
155 template <class _Iter1
, class _Iter2
>
156 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
157 bool operator>(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter2
>& __y
) _NOEXCEPT
162 template <class _Iter1
>
163 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
164 bool operator>=(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter1
>& __y
) _NOEXCEPT
169 template <class _Iter1
, class _Iter2
>
170 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
171 bool operator>=(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter2
>& __y
) _NOEXCEPT
176 template <class _Iter1
>
177 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
178 bool operator<=(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter1
>& __y
) _NOEXCEPT
183 template <class _Iter1
, class _Iter2
>
184 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
185 bool operator<=(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter2
>& __y
) _NOEXCEPT
190 template <class _Iter1
, class _Iter2
>
191 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
192 #ifndef _LIBCPP_CXX03_LANG
193 auto operator-(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter2
>& __y
) _NOEXCEPT
194 -> decltype(__x
.base() - __y
.base())
196 typename __wrap_iter
<_Iter1
>::difference_type
197 operator-(const __wrap_iter
<_Iter1
>& __x
, const __wrap_iter
<_Iter2
>& __y
) _NOEXCEPT
200 return __x
.base() - __y
.base();
203 template <class _Iter1
>
204 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
205 __wrap_iter
<_Iter1
> operator+(typename __wrap_iter
<_Iter1
>::difference_type __n
, __wrap_iter
<_Iter1
> __x
) _NOEXCEPT
211 #if _LIBCPP_STD_VER <= 17
213 struct __libcpp_is_contiguous_iterator
<__wrap_iter
<_It
> > : true_type
{};
217 struct _LIBCPP_TEMPLATE_VIS pointer_traits
<__wrap_iter
<_It
> >
219 typedef __wrap_iter
<_It
> pointer
;
220 typedef typename pointer_traits
<_It
>::element_type element_type
;
221 typedef typename pointer_traits
<_It
>::difference_type difference_type
;
223 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
224 static element_type
*to_address(pointer __w
) _NOEXCEPT
{
225 return _VSTD::__to_address(__w
.base());
229 _LIBCPP_END_NAMESPACE_STD
231 #endif // _LIBCPP___ITERATOR_WRAP_ITER_H