Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __iterator / iterator_with_data.h
blob06c2fa699c30eb887aa06fb90430d3d5e4048301
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 //===----------------------------------------------------------------------===//
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>
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>
23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24 # pragma GCC system_header
25 #endif
27 #if _LIBCPP_STD_VER >= 20
29 _LIBCPP_BEGIN_NAMESPACE_STD
31 template <forward_iterator _Iterator, class _Data>
32 class __iterator_with_data {
33 _Iterator __iter_{};
34 _Data __data_{};
36 public:
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++() {
55 ++__iter_;
56 return *this;
59 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data operator++(int) {
60 auto __tmp = *this;
61 __iter_++;
62 return __tmp;
65 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data& operator--()
66 requires bidirectional_iterator<_Iterator>
68 --__iter_;
69 return *this;
72 constexpr _LIBCPP_HIDE_FROM_ABI __iterator_with_data operator--(int)
73 requires bidirectional_iterator<_Iterator>
75 auto __tmp = *this;
76 --__iter_;
77 return __tmp;
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