File indexing completed on 2026-05-03 08:13:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___ITERATOR_WRAP_ITER_H
0011 #define _LIBCPP___CXX03___ITERATOR_WRAP_ITER_H
0012
0013 #include <__cxx03/__compare/ordering.h>
0014 #include <__cxx03/__compare/three_way_comparable.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__iterator/iterator_traits.h>
0017 #include <__cxx03/__memory/addressof.h>
0018 #include <__cxx03/__memory/pointer_traits.h>
0019 #include <__cxx03/__type_traits/enable_if.h>
0020 #include <__cxx03/__type_traits/is_convertible.h>
0021 #include <__cxx03/cstddef>
0022
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 # pragma GCC system_header
0025 #endif
0026
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028
0029 template <class _Iter>
0030 class __wrap_iter {
0031 public:
0032 typedef _Iter iterator_type;
0033 typedef typename iterator_traits<iterator_type>::value_type value_type;
0034 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
0035 typedef typename iterator_traits<iterator_type>::pointer pointer;
0036 typedef typename iterator_traits<iterator_type>::reference reference;
0037 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
0038 #if _LIBCPP_STD_VER >= 20
0039 typedef contiguous_iterator_tag iterator_concept;
0040 #endif
0041
0042 private:
0043 iterator_type __i_;
0044
0045 public:
0046 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter() _NOEXCEPT : __i_() {}
0047 template <class _Up, __enable_if_t<is_convertible<_Up, iterator_type>::value, int> = 0>
0048 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter(const __wrap_iter<_Up>& __u) _NOEXCEPT
0049 : __i_(__u.base()) {}
0050 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { return *__i_; }
0051 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pointer operator->() const _NOEXCEPT {
0052 return std::__to_address(__i_);
0053 }
0054 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter& operator++() _NOEXCEPT {
0055 ++__i_;
0056 return *this;
0057 }
0058 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter operator++(int) _NOEXCEPT {
0059 __wrap_iter __tmp(*this);
0060 ++(*this);
0061 return __tmp;
0062 }
0063
0064 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter& operator--() _NOEXCEPT {
0065 --__i_;
0066 return *this;
0067 }
0068 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter operator--(int) _NOEXCEPT {
0069 __wrap_iter __tmp(*this);
0070 --(*this);
0071 return __tmp;
0072 }
0073 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter operator+(difference_type __n) const _NOEXCEPT {
0074 __wrap_iter __w(*this);
0075 __w += __n;
0076 return __w;
0077 }
0078 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter& operator+=(difference_type __n) _NOEXCEPT {
0079 __i_ += __n;
0080 return *this;
0081 }
0082 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter operator-(difference_type __n) const _NOEXCEPT {
0083 return *this + (-__n);
0084 }
0085 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter& operator-=(difference_type __n) _NOEXCEPT {
0086 *this += -__n;
0087 return *this;
0088 }
0089 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT {
0090 return __i_[__n];
0091 }
0092
0093 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 iterator_type base() const _NOEXCEPT { return __i_; }
0094
0095 private:
0096 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __wrap_iter(iterator_type __x) _NOEXCEPT : __i_(__x) {}
0097
0098 template <class _Up>
0099 friend class __wrap_iter;
0100 template <class _CharT, class _Traits, class _Alloc>
0101 friend class basic_string;
0102 template <class _CharT, class _Traits>
0103 friend class basic_string_view;
0104 template <class _Tp, class _Alloc>
0105 friend class _LIBCPP_TEMPLATE_VIS vector;
0106 template <class _Tp, size_t>
0107 friend class _LIBCPP_TEMPLATE_VIS span;
0108 template <class _Tp, size_t _Size>
0109 friend struct array;
0110 };
0111
0112 template <class _Iter1>
0113 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0114 operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
0115 return __x.base() == __y.base();
0116 }
0117
0118 template <class _Iter1, class _Iter2>
0119 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0120 operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
0121 return __x.base() == __y.base();
0122 }
0123
0124 template <class _Iter1>
0125 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
0126 operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
0127 return __x.base() < __y.base();
0128 }
0129
0130 template <class _Iter1, class _Iter2>
0131 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
0132 operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
0133 return __x.base() < __y.base();
0134 }
0135
0136 #if _LIBCPP_STD_VER <= 17
0137 template <class _Iter1>
0138 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0139 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
0140 return !(__x == __y);
0141 }
0142
0143 template <class _Iter1, class _Iter2>
0144 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0145 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
0146 return !(__x == __y);
0147 }
0148 #endif
0149
0150
0151 template <class _Iter1>
0152 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0153 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
0154 return __y < __x;
0155 }
0156
0157 template <class _Iter1, class _Iter2>
0158 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0159 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
0160 return __y < __x;
0161 }
0162
0163 template <class _Iter1>
0164 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0165 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
0166 return !(__x < __y);
0167 }
0168
0169 template <class _Iter1, class _Iter2>
0170 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0171 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
0172 return !(__x < __y);
0173 }
0174
0175 template <class _Iter1>
0176 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0177 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
0178 return !(__y < __x);
0179 }
0180
0181 template <class _Iter1, class _Iter2>
0182 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
0183 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
0184 return !(__y < __x);
0185 }
0186
0187 #if _LIBCPP_STD_VER >= 20
0188 template <class _Iter1, class _Iter2>
0189 _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
0190 operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept {
0191 if constexpr (three_way_comparable_with<_Iter1, _Iter2, strong_ordering>) {
0192 return __x.base() <=> __y.base();
0193 } else {
0194 if (__x.base() < __y.base())
0195 return strong_ordering::less;
0196
0197 if (__x.base() == __y.base())
0198 return strong_ordering::equal;
0199
0200 return strong_ordering::greater;
0201 }
0202 }
0203 #endif
0204
0205 template <class _Iter1, class _Iter2>
0206 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
0207 #ifndef _LIBCPP_CXX03_LANG
0208 auto
0209 operator-(const __wrap_iter<_Iter1>& __x,
0210 const __wrap_iter<_Iter2>& __y) _NOEXCEPT->decltype(__x.base() - __y.base())
0211 #else
0212 typename __wrap_iter<_Iter1>::difference_type
0213 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
0214 #endif
0215 {
0216 return __x.base() - __y.base();
0217 }
0218
0219 template <class _Iter1>
0220 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter<_Iter1>
0221 operator+(typename __wrap_iter<_Iter1>::difference_type __n, __wrap_iter<_Iter1> __x) _NOEXCEPT {
0222 __x += __n;
0223 return __x;
0224 }
0225
0226 #if _LIBCPP_STD_VER <= 17
0227 template <class _It>
0228 struct __libcpp_is_contiguous_iterator<__wrap_iter<_It> > : true_type {};
0229 #endif
0230
0231 template <class _It>
0232 struct _LIBCPP_TEMPLATE_VIS pointer_traits<__wrap_iter<_It> > {
0233 typedef __wrap_iter<_It> pointer;
0234 typedef typename pointer_traits<_It>::element_type element_type;
0235 typedef typename pointer_traits<_It>::difference_type difference_type;
0236
0237 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static element_type* to_address(pointer __w) _NOEXCEPT {
0238 return std::__to_address(__w.base());
0239 }
0240 };
0241
0242 _LIBCPP_END_NAMESPACE_STD
0243
0244 #endif