Back to home page

EIC code displayed by LXR

 
 

    


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

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___FLAT_MAP_KEY_VALUE_ITERATOR_H
0011 #define _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H
0012 
0013 #include <__compare/three_way_comparable.h>
0014 #include <__concepts/convertible_to.h>
0015 #include <__config>
0016 #include <__iterator/iterator_traits.h>
0017 #include <__memory/addressof.h>
0018 #include <__type_traits/conditional.h>
0019 #include <__utility/move.h>
0020 #include <__utility/pair.h>
0021 
0022 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0023 #  pragma GCC system_header
0024 #endif
0025 
0026 _LIBCPP_PUSH_MACROS
0027 #include <__undef_macros>
0028 
0029 #if _LIBCPP_STD_VER >= 23
0030 
0031 _LIBCPP_BEGIN_NAMESPACE_STD
0032 
0033 /**
0034  * __key_value_iterator is a proxy iterator which zips the underlying
0035  * _KeyContainer::iterator and the underlying _MappedContainer::iterator.
0036  * The two underlying iterators will be incremented/decremented together.
0037  * And the reference is a pair of the const key reference and the value reference.
0038  */
0039 template <class _Owner, class _KeyContainer, class _MappedContainer, bool _Const>
0040 struct __key_value_iterator {
0041 private:
0042   using __key_iterator _LIBCPP_NODEBUG = typename _KeyContainer::const_iterator;
0043   using __mapped_iterator _LIBCPP_NODEBUG =
0044       _If<_Const, typename _MappedContainer::const_iterator, typename _MappedContainer::iterator>;
0045   using __reference _LIBCPP_NODEBUG = _If<_Const, typename _Owner::const_reference, typename _Owner::reference>;
0046 
0047   struct __arrow_proxy {
0048     __reference __ref_;
0049     _LIBCPP_HIDE_FROM_ABI __reference* operator->() { return std::addressof(__ref_); }
0050   };
0051 
0052   __key_iterator __key_iter_;
0053   __mapped_iterator __mapped_iter_;
0054 
0055   friend _Owner;
0056 
0057   template <class, class, class, bool>
0058   friend struct __key_value_iterator;
0059 
0060 public:
0061   using iterator_concept = random_access_iterator_tag;
0062   // `__key_value_iterator` only satisfy "Cpp17InputIterator" named requirements, because
0063   // its `reference` is not a reference type.
0064   // However, to avoid surprising runtime behaviour when it is used with the
0065   // Cpp17 algorithms or operations, iterator_category is set to random_access_iterator_tag.
0066   using iterator_category = random_access_iterator_tag;
0067   using value_type        = typename _Owner::value_type;
0068   using difference_type   = typename _Owner::difference_type;
0069 
0070   _LIBCPP_HIDE_FROM_ABI __key_value_iterator() = default;
0071 
0072   _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_value_iterator<_Owner, _KeyContainer, _MappedContainer, !_Const> __i)
0073     requires _Const && convertible_to<typename _KeyContainer::iterator, __key_iterator> &&
0074                  convertible_to<typename _MappedContainer::iterator, __mapped_iterator>
0075       : __key_iter_(std::move(__i.__key_iter_)), __mapped_iter_(std::move(__i.__mapped_iter_)) {}
0076 
0077   _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_iterator __key_iter, __mapped_iterator __mapped_iter)
0078       : __key_iter_(std::move(__key_iter)), __mapped_iter_(std::move(__mapped_iter)) {}
0079 
0080   _LIBCPP_HIDE_FROM_ABI __reference operator*() const { return __reference(*__key_iter_, *__mapped_iter_); }
0081   _LIBCPP_HIDE_FROM_ABI __arrow_proxy operator->() const { return __arrow_proxy{**this}; }
0082 
0083   _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator++() {
0084     ++__key_iter_;
0085     ++__mapped_iter_;
0086     return *this;
0087   }
0088 
0089   _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator++(int) {
0090     __key_value_iterator __tmp(*this);
0091     ++*this;
0092     return __tmp;
0093   }
0094 
0095   _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator--() {
0096     --__key_iter_;
0097     --__mapped_iter_;
0098     return *this;
0099   }
0100 
0101   _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator--(int) {
0102     __key_value_iterator __tmp(*this);
0103     --*this;
0104     return __tmp;
0105   }
0106 
0107   _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator+=(difference_type __x) {
0108     __key_iter_ += __x;
0109     __mapped_iter_ += __x;
0110     return *this;
0111   }
0112 
0113   _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator-=(difference_type __x) {
0114     __key_iter_ -= __x;
0115     __mapped_iter_ -= __x;
0116     return *this;
0117   }
0118 
0119   _LIBCPP_HIDE_FROM_ABI __reference operator[](difference_type __n) const { return *(*this + __n); }
0120 
0121   _LIBCPP_HIDE_FROM_ABI friend constexpr bool
0122   operator==(const __key_value_iterator& __x, const __key_value_iterator& __y) {
0123     return __x.__key_iter_ == __y.__key_iter_;
0124   }
0125 
0126   _LIBCPP_HIDE_FROM_ABI friend bool operator<(const __key_value_iterator& __x, const __key_value_iterator& __y) {
0127     return __x.__key_iter_ < __y.__key_iter_;
0128   }
0129 
0130   _LIBCPP_HIDE_FROM_ABI friend bool operator>(const __key_value_iterator& __x, const __key_value_iterator& __y) {
0131     return __y < __x;
0132   }
0133 
0134   _LIBCPP_HIDE_FROM_ABI friend bool operator<=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
0135     return !(__y < __x);
0136   }
0137 
0138   _LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
0139     return !(__x < __y);
0140   }
0141 
0142   _LIBCPP_HIDE_FROM_ABI friend auto operator<=>(const __key_value_iterator& __x, const __key_value_iterator& __y)
0143     requires three_way_comparable<__key_iterator>
0144   {
0145     return __x.__key_iter_ <=> __y.__key_iter_;
0146   }
0147 
0148   _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(const __key_value_iterator& __i, difference_type __n) {
0149     auto __tmp = __i;
0150     __tmp += __n;
0151     return __tmp;
0152   }
0153 
0154   _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(difference_type __n, const __key_value_iterator& __i) {
0155     return __i + __n;
0156   }
0157 
0158   _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator-(const __key_value_iterator& __i, difference_type __n) {
0159     auto __tmp = __i;
0160     __tmp -= __n;
0161     return __tmp;
0162   }
0163 
0164   _LIBCPP_HIDE_FROM_ABI friend difference_type
0165   operator-(const __key_value_iterator& __x, const __key_value_iterator& __y) {
0166     return difference_type(__x.__key_iter_ - __y.__key_iter_);
0167   }
0168 };
0169 
0170 _LIBCPP_END_NAMESPACE_STD
0171 
0172 #endif // _LIBCPP_STD_VER >= 23
0173 
0174 _LIBCPP_POP_MACROS
0175 
0176 #endif // _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H