File indexing completed on 2026-05-03 08:13:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___ITERATOR_NEXT_H
0011 #define _LIBCPP___ITERATOR_NEXT_H
0012
0013 #include <__assert>
0014 #include <__config>
0015 #include <__iterator/advance.h>
0016 #include <__iterator/concepts.h>
0017 #include <__iterator/incrementable_traits.h>
0018 #include <__iterator/iterator_traits.h>
0019 #include <__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 [[__nodiscard__]] 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 struct __next {
0045 template <input_or_output_iterator _Ip>
0046 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {
0047 ++__x;
0048 return __x;
0049 }
0050
0051 template <input_or_output_iterator _Ip>
0052 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {
0053 ranges::advance(__x, __n);
0054 return __x;
0055 }
0056
0057 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
0058 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const {
0059 ranges::advance(__x, __bound_sentinel);
0060 return __x;
0061 }
0062
0063 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
0064 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip
0065 operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const {
0066 ranges::advance(__x, __n, __bound_sentinel);
0067 return __x;
0068 }
0069 };
0070
0071 inline namespace __cpo {
0072 inline constexpr auto next = __next{};
0073 }
0074 }
0075
0076 #endif
0077
0078 _LIBCPP_END_NAMESPACE_STD
0079
0080 #endif