diff options
author | Konstantin Varlamov <varconst@apple.com> | 2022-08-03 16:04:14 -0700 |
---|---|---|
committer | Konstantin Varlamov <varconst@apple.com> | 2022-08-03 16:04:24 -0700 |
commit | 36c746ca2d5b325a7ac64135c1ff8774c06ab34c (patch) | |
tree | c081b21b9c5211da27c90966c72fb81232c72296 /libcxx/include/__algorithm/iterator_operations.h | |
parent | 42c15ca630126cafdd646ac3874fc6b1a110a8ca (diff) | |
download | llvm-36c746ca2d5b325a7ac64135c1ff8774c06ab34c.tar.gz |
[libc++][ranges] Implement `ranges::rotate`.
Also fix `ranges::stable_sort` and `ranges::inplace_merge` to support
proxy iterators now that their internal implementations can correctly
dispatch `rotate`.
Differential Revision: https://reviews.llvm.org/D130758
Diffstat (limited to 'libcxx/include/__algorithm/iterator_operations.h')
-rw-r--r-- | libcxx/include/__algorithm/iterator_operations.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/libcxx/include/__algorithm/iterator_operations.h b/libcxx/include/__algorithm/iterator_operations.h index 2222b9883d60..af461878737f 100644 --- a/libcxx/include/__algorithm/iterator_operations.h +++ b/libcxx/include/__algorithm/iterator_operations.h @@ -19,6 +19,7 @@ #include <__iterator/iter_swap.h> #include <__iterator/iterator_traits.h> #include <__iterator/next.h> +#include <__iterator/prev.h> #include <__iterator/readable_traits.h> #include <__utility/declval.h> #include <__utility/forward.h> @@ -53,6 +54,7 @@ struct _IterOps<_RangeAlgPolicy> { static constexpr auto __iter_move = ranges::iter_move; static constexpr auto iter_swap = ranges::iter_swap; static constexpr auto next = ranges::next; + static constexpr auto prev = ranges::prev; static constexpr auto __advance_to = ranges::advance; }; @@ -146,10 +148,18 @@ struct _IterOps<_ClassicAlgPolicy> { template <class _Iter> _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 __uncvref_t<_Iter> next(_Iter&& __it, - typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1){ + typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1) { return std::next(std::forward<_Iter>(__it), __n); } + // prev + template <class _Iter> + _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 + __uncvref_t<_Iter> prev(_Iter&& __iter, + typename iterator_traits<__uncvref_t<_Iter> >::difference_type __n = 1) { + return std::prev(std::forward<_Iter>(__iter), __n); + } + template <class _Iter> _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 void __advance_to(_Iter& __first, _Iter __last) { |