Path: blob/main/contrib/llvm-project/libcxx/include/__iterator/next.h
35233 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___ITERATOR_NEXT_H10#define _LIBCPP___ITERATOR_NEXT_H1112#include <__assert>13#include <__config>14#include <__iterator/advance.h>15#include <__iterator/concepts.h>16#include <__iterator/incrementable_traits.h>17#include <__iterator/iterator_traits.h>18#include <__type_traits/enable_if.h>1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)21# pragma GCC system_header22#endif2324_LIBCPP_BEGIN_NAMESPACE_STD2526template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>27inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter28next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) {29// Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.30// Note that this check duplicates the similar check in `std::advance`.31_LIBCPP_ASSERT_PEDANTIC(__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value,32"Attempt to next(it, n) with negative n on a non-bidirectional iterator");3334std::advance(__x, __n);35return __x;36}3738#if _LIBCPP_STD_VER >= 203940// [range.iter.op.next]4142namespace ranges {43namespace __next {4445struct __fn {46template <input_or_output_iterator _Ip>47_LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {48++__x;49return __x;50}5152template <input_or_output_iterator _Ip>53_LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {54ranges::advance(__x, __n);55return __x;56}5758template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>59_LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const {60ranges::advance(__x, __bound_sentinel);61return __x;62}6364template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>65_LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const {66ranges::advance(__x, __n, __bound_sentinel);67return __x;68}69};7071} // namespace __next7273inline namespace __cpo {74inline constexpr auto next = __next::__fn{};75} // namespace __cpo76} // namespace ranges7778#endif // _LIBCPP_STD_VER >= 207980_LIBCPP_END_NAMESPACE_STD8182#endif // _LIBCPP___ITERATOR_NEXT_H838485