1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___ITERATOR_ITERATOR_WITH_DATA_H
10 #define _LIBCPP___ITERATOR_ITERATOR_WITH_DATA_H
12 #include <__compare/compare_three_way_result.h>
13 #include <__compare/three_way_comparable.h>
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>
23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24 # pragma GCC system_header
27 #if _LIBCPP_STD_VER >= 20
29 _LIBCPP_BEGIN_NAMESPACE_STD
31 template <forward_iterator _Iterator
, class _Data
>
32 class __iterator_with_data
{
37 using value_type
= iter_value_t
<_Iterator
>;
38 using difference_type
= iter_difference_t
<_Iterator
>;
40 _LIBCPP_HIDE_FROM_ABI
__iterator_with_data() = default;
42 constexpr _LIBCPP_HIDE_FROM_ABI
__iterator_with_data(_Iterator __iter
, _Data __data
)
43 : __iter_(std::move(__iter
)), __data_(std::move(__data
)) {}
45 constexpr _LIBCPP_HIDE_FROM_ABI _Iterator
__get_iter() const { return __iter_
; }
47 constexpr _LIBCPP_HIDE_FROM_ABI _Data
__get_data() && { return std::move(__data_
); }
49 friend constexpr _LIBCPP_HIDE_FROM_ABI
bool
50 operator==(const __iterator_with_data
& __lhs
, const __iterator_with_data
& __rhs
) {
51 return __lhs
.__iter_
== __rhs
.__iter_
;
54 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data
& operator++() {
59 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data
operator++(int) {
65 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data
& operator--()
66 requires bidirectional_iterator
<_Iterator
>
72 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data
operator--(int)
73 requires bidirectional_iterator
<_Iterator
>
80 constexpr _LIBCPP_HIDE_FROM_ABI iter_reference_t
<_Iterator
> operator*() const { return *__iter_
; }
82 _LIBCPP_HIDE_FROM_ABI
friend constexpr iter_rvalue_reference_t
<_Iterator
>
83 iter_move(const __iterator_with_data
& __iter
) noexcept(noexcept(ranges::iter_move(__iter
.__iter_
))) {
84 return ranges::iter_move(__iter
.__iter_
);
87 _LIBCPP_HIDE_FROM_ABI
friend constexpr void
88 iter_swap(const __iterator_with_data
& __lhs
,
89 const __iterator_with_data
& __rhs
) noexcept(noexcept(ranges::iter_swap(__lhs
.__iter_
, __rhs
.__iter_
)))
90 requires indirectly_swappable
<_Iterator
>
92 return ranges::iter_swap(__lhs
.__data_
, __rhs
.__iter_
);
96 _LIBCPP_END_NAMESPACE_STD
98 #endif // _LIBCPP_STD_VER >= 20
100 #endif // _LIBCPP___ITERATOR_ITERATOR_WITH_DATA_H