Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:33

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
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   // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
0031   // Note that this check duplicates the similar check in `std::advance`.
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 // [range.iter.op.next]
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 } // namespace __next
0073 
0074 inline namespace __cpo {
0075 inline constexpr auto next = __next::__fn{};
0076 } // namespace __cpo
0077 } // namespace ranges
0078 
0079 #endif // _LIBCPP_STD_VER >= 20
0080 
0081 _LIBCPP_END_NAMESPACE_STD
0082 
0083 #endif // _LIBCPP___CXX03___ITERATOR_NEXT_H