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
28 #include <__undef_macros>
30 #if _LIBCPP_STD_VER >= 20
32 _LIBCPP_BEGIN_NAMESPACE_STD
34 template <forward_iterator _Iterator
, class _Data
>
35 class __iterator_with_data
{
40 using value_type
= iter_value_t
<_Iterator
>;
41 using difference_type
= iter_difference_t
<_Iterator
>;
43 _LIBCPP_HIDE_FROM_ABI
__iterator_with_data() = default;
45 constexpr _LIBCPP_HIDE_FROM_ABI
__iterator_with_data(_Iterator __iter
, _Data __data
)
46 : __iter_(std::move(__iter
)), __data_(std::move(__data
)) {}
48 constexpr _LIBCPP_HIDE_FROM_ABI _Iterator
__get_iter() const { return __iter_
; }
50 constexpr _LIBCPP_HIDE_FROM_ABI _Data
__get_data() && { return std::move(__data_
); }
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_
;
57 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data
& operator++() {
62 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data
operator++(int) {
68 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data
& operator--()
69 requires bidirectional_iterator
<_Iterator
>
75 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data
operator--(int)
76 requires bidirectional_iterator
<_Iterator
>
83 constexpr _LIBCPP_HIDE_FROM_ABI iter_reference_t
<_Iterator
> operator*() const { return *__iter_
; }
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_
);
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
>
95 return ranges::iter_swap(__lhs
.__data_
, __rhs
.__iter_
);
99 _LIBCPP_END_NAMESPACE_STD
101 #endif // _LIBCPP_STD_VER >= 20
105 #endif // _LIBCPP___ITERATOR_ITERATOR_WITH_DATA_H