| 1 |
// -*- C++ -*- |
| 2 |
//===----------------------------------------------------------------------===// |
| 3 |
// |
| 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 |
| 7 |
// |
| 8 |
//===----------------------------------------------------------------------===// |
| 9 |
|
| 10 |
#ifndef _LIBCPP___CXX03___ITERATOR_NEXT_H |
| 11 |
#define _LIBCPP___CXX03___ITERATOR_NEXT_H |
| 12 |
|
| 13 |
#include <__cxx03/__assert> |
| 14 |
#include <__cxx03/__config> |
| 15 |
#include <__cxx03/__iterator/advance.h> |
| 16 |
#include <__cxx03/__iterator/iterator_traits.h> |
| 17 |
#include <__cxx03/__type_traits/enable_if.h> |
| 18 |
|
| 19 |
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 20 |
# pragma GCC system_header |
| 21 |
#endif |
| 22 |
|
| 23 |
_LIBCPP_BEGIN_NAMESPACE_STD |
| 24 |
|
| 25 |
template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0> |
| 26 |
inline _LIBCPP_HIDE_FROM_ABI _InputIter |
| 27 |
next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) { |
| 28 |
// Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation. |
| 29 |
// Note that this check duplicates the similar check in `std::advance`. |
| 30 |
_LIBCPP_ASSERT_PEDANTIC(__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value, |
| 31 |
"Attempt to next(it, n) with negative n on a non-bidirectional iterator"); |
| 32 |
|
| 33 |
std::advance(__x, __n); |
| 34 |
return __x; |
| 35 |
} |
| 36 |
|
| 37 |
_LIBCPP_END_NAMESPACE_STD |
| 38 |
|
| 39 |
#endif // _LIBCPP___CXX03___ITERATOR_NEXT_H |