File indexing completed on 2026-05-03 08:13:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___ITERATOR_NEXT_H
0011 #define _LIBCPP___CXX03___ITERATOR_NEXT_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 next(_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 next(it, n) with negative n on a non-bidirectional iterator");
0034
0035 std::advance(__x, __n);
0036 return __x;
0037 }
0038
0039 #if _LIBCPP_STD_VER >= 20
0040
0041
0042
0043 namespace ranges {
0044 namespace __next {
0045
0046 struct __fn {
0047 template <input_or_output_iterator _Ip>
0048 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {
0049 ++__x;
0050 return __x;
0051 }
0052
0053 template <input_or_output_iterator _Ip>
0054 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {
0055 ranges::advance(__x, __n);
0056 return __x;
0057 }
0058
0059 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
0060 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const {
0061 ranges::advance(__x, __bound_sentinel);
0062 return __x;
0063 }
0064
0065 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
0066 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const {
0067 ranges::advance(__x, __n, __bound_sentinel);
0068 return __x;
0069 }
0070 };
0071
0072 }
0073
0074 inline namespace __cpo {
0075 inline constexpr auto next = __next::__fn{};
0076 }
0077 }
0078
0079 #endif
0080
0081 _LIBCPP_END_NAMESPACE_STD
0082
0083 #endif