| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#ifndef _LIBCPP___ITERATOR_ITERATOR_WITH_DATA_H |
| 10 |
#define _LIBCPP___ITERATOR_ITERATOR_WITH_DATA_H |
| 11 |
|
| 12 |
#include <__compare/compare_three_way_result.h> |
| 13 |
#include <__compare/three_way_comparable.h> |
| 14 |
#include <__config> |
| 15 |
#include <__iterator/concepts.h> |
| 16 |
#include <__iterator/incrementable_traits.h> |
| 17 |
#include <__iterator/iter_move.h> |
| 18 |
#include <__iterator/iter_swap.h> |
| 19 |
#include <__iterator/iterator_traits.h> |
| 20 |
#include <__iterator/readable_traits.h> |
| 21 |
#include <__utility/move.h> |
| 22 |
|
| 23 |
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 24 |
# pragma GCC system_header |
| 25 |
#endif |
| 26 |
|
| 27 |
_LIBCPP_PUSH_MACROS |
| 28 |
#include <__undef_macros> |
| 29 |
|
| 30 |
#if _LIBCPP_STD_VER >= 20 |
| 31 |
|
| 32 |
_LIBCPP_BEGIN_NAMESPACE_STD |
| 33 |
|
| 34 |
template <forward_iterator _Iterator, class _Data> |
| 35 |
class __iterator_with_data { |
| 36 |
_Iterator __iter_{}; |
| 37 |
_Data __data_{}; |
| 38 |
|
| 39 |
public: |
| 40 |
using value_type = iter_value_t<_Iterator>; |
| 41 |
using difference_type = iter_difference_t<_Iterator>; |
| 42 |
|
| 43 |
_LIBCPP_HIDE_FROM_ABI __iterator_with_data() = default; |
| 44 |
|
| 45 |
constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data(_Iterator __iter, _Data __data) |
| 46 |
: __iter_(std::move(__iter)), __data_(std::move(__data)) {} |
| 47 |
|
| 48 |
constexpr _LIBCPP_HIDE_FROM_ABI _Iterator __get_iter() const { return __iter_; } |
| 49 |
|
| 50 |
constexpr _LIBCPP_HIDE_FROM_ABI _Data __get_data() && { return std::move(__data_); } |
| 51 |
|
| 52 |
friend constexpr _LIBCPP_HIDE_FROM_ABI bool |
| 53 |
operator==(const __iterator_with_data& __lhs, const __iterator_with_data& __rhs) { |
| 54 |
return __lhs.__iter_ == __rhs.__iter_; |
| 55 |
} |
| 56 |
|
| 57 |
constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data& operator++() { |
| 58 |
++__iter_; |
| 59 |
return *this; |
| 60 |
} |
| 61 |
|
| 62 |
constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data operator++(int) { |
| 63 |
auto __tmp = *this; |
| 64 |
__iter_++; |
| 65 |
return __tmp; |
| 66 |
} |
| 67 |
|
| 68 |
constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data& operator--() |
| 69 |
requires bidirectional_iterator<_Iterator> |
| 70 |
{ |
| 71 |
--__iter_; |
| 72 |
return *this; |
| 73 |
} |
| 74 |
|
| 75 |
constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data operator--(int) |
| 76 |
requires bidirectional_iterator<_Iterator> |
| 77 |
{ |
| 78 |
auto __tmp = *this; |
| 79 |
--__iter_; |
| 80 |
return __tmp; |
| 81 |
} |
| 82 |
|
| 83 |
constexpr _LIBCPP_HIDE_FROM_ABI iter_reference_t<_Iterator> operator*() const { return *__iter_; } |
| 84 |
|
| 85 |
_LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iterator> |
| 86 |
iter_move(const __iterator_with_data& __iter) noexcept(noexcept(ranges::iter_move(__iter.__iter_))) { |
| 87 |
return ranges::iter_move(__iter.__iter_); |
| 88 |
} |
| 89 |
|
| 90 |
_LIBCPP_HIDE_FROM_ABI friend constexpr void |
| 91 |
iter_swap(const __iterator_with_data& __lhs, |
| 92 |
const __iterator_with_data& __rhs) noexcept(noexcept(ranges::iter_swap(__lhs.__iter_, __rhs.__iter_))) |
| 93 |
requires indirectly_swappable<_Iterator> |
| 94 |
{ |
| 95 |
return ranges::iter_swap(__lhs.__data_, __rhs.__iter_); |
| 96 |
} |
| 97 |
}; |
| 98 |
|
| 99 |
_LIBCPP_END_NAMESPACE_STD |
| 100 |
|
| 101 |
#endif // _LIBCPP_STD_VER >= 20 |
| 102 |
|
| 103 |
_LIBCPP_POP_MACROS |
| 104 |
|
| 105 |
#endif // _LIBCPP___ITERATOR_ITERATOR_WITH_DATA_H |