Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:54

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