2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___ITERATOR_NEXT_H
11 #define _LIBCPP___ITERATOR_NEXT_H
15 #include <__iterator/advance.h>
16 #include <__iterator/concepts.h>
17 #include <__iterator/incrementable_traits.h>
18 #include <__iterator/iterator_traits.h>
19 #include <__type_traits/enable_if.h>
21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22 # pragma GCC system_header
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 template <class _InputIter
, __enable_if_t
<__has_input_iterator_category
<_InputIter
>::value
, int> = 0>
28 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
30 next(_InputIter __x
, typename iterator_traits
<_InputIter
>::difference_type __n
= 1) {
31 _LIBCPP_ASSERT_UNCATEGORIZED(__n
>= 0 || __has_bidirectional_iterator_category
<_InputIter
>::value
,
32 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
34 _VSTD::advance(__x
, __n
);
38 #if _LIBCPP_STD_VER >= 20
40 // [range.iter.op.next]
46 template <input_or_output_iterator _Ip
>
48 constexpr _Ip
operator()(_Ip __x
) const {
53 template <input_or_output_iterator _Ip
>
55 constexpr _Ip
operator()(_Ip __x
, iter_difference_t
<_Ip
> __n
) const {
56 ranges::advance(__x
, __n
);
60 template <input_or_output_iterator _Ip
, sentinel_for
<_Ip
> _Sp
>
61 _LIBCPP_HIDE_FROM_ABI
constexpr _Ip
operator()(_Ip __x
, _Sp __bound_sentinel
) const {
62 ranges::advance(__x
, __bound_sentinel
);
66 template <input_or_output_iterator _Ip
, sentinel_for
<_Ip
> _Sp
>
67 _LIBCPP_HIDE_FROM_ABI
constexpr _Ip
operator()(_Ip __x
, iter_difference_t
<_Ip
> __n
, _Sp __bound_sentinel
) const {
68 ranges::advance(__x
, __n
, __bound_sentinel
);
75 inline namespace __cpo
{
76 inline constexpr auto next
= __next::__fn
{};
80 #endif // _LIBCPP_STD_VER >= 20
82 _LIBCPP_END_NAMESPACE_STD
84 #endif // _LIBCPP___ITERATOR_NEXT_H