File indexing completed on 2026-05-03 08:13:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___ITERATOR_PREV_H
0011 #define _LIBCPP___CXX03___ITERATOR_PREV_H
0012
0013 #include <__cxx03/__assert>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__iterator/advance.h>
0016 #include <__cxx03/__iterator/concepts.h>
0017 #include <__cxx03/__iterator/incrementable_traits.h>
0018 #include <__cxx03/__iterator/iterator_traits.h>
0019 #include <__cxx03/__type_traits/enable_if.h>
0020
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 # pragma GCC system_header
0023 #endif
0024
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026
0027 template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
0028 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter
0029 prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) {
0030
0031
0032 _LIBCPP_ASSERT_PEDANTIC(__n <= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
0033 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
0034 std::advance(__x, -__n);
0035 return __x;
0036 }
0037
0038 #if _LIBCPP_STD_VER >= 20
0039
0040
0041
0042 namespace ranges {
0043 namespace __prev {
0044
0045 struct __fn {
0046 template <bidirectional_iterator _Ip>
0047 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {
0048 --__x;
0049 return __x;
0050 }
0051
0052 template <bidirectional_iterator _Ip>
0053 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {
0054 ranges::advance(__x, -__n);
0055 return __x;
0056 }
0057
0058 template <bidirectional_iterator _Ip>
0059 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound_iter) const {
0060 ranges::advance(__x, -__n, __bound_iter);
0061 return __x;
0062 }
0063 };
0064
0065 }
0066
0067 inline namespace __cpo {
0068 inline constexpr auto prev = __prev::__fn{};
0069 }
0070 }
0071
0072 #endif
0073
0074 _LIBCPP_END_NAMESPACE_STD
0075
0076 #endif