[libcxx-commits] [libcxx] bf92bda - [libcxx][nfc] moves std `advance`, `next`, and `prev` into their headers
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Mon May 31 10:16:00 PDT 2021
Author: Christopher Di Bella
Date: 2021-05-31T17:14:52Z
New Revision: bf92bdad77a34770fe0541a750f9cd3a61f169a3
URL: https://github.com/llvm/llvm-project/commit/bf92bdad77a34770fe0541a750f9cd3a61f169a3
DIFF: https://github.com/llvm/llvm-project/commit/bf92bdad77a34770fe0541a750f9cd3a61f169a3.diff
LOG: [libcxx][nfc] moves std `advance`, `next`, and `prev` into their headers
Differential Revision: https://reviews.llvm.org/D103329
Added:
Modified:
libcxx/include/__iterator/advance.h
libcxx/include/__iterator/next.h
libcxx/include/__iterator/prev.h
libcxx/include/iterator
Removed:
################################################################################
diff --git a/libcxx/include/__iterator/advance.h b/libcxx/include/__iterator/advance.h
index 3591b9da0eef..f482d18d602e 100644
--- a/libcxx/include/__iterator/advance.h
+++ b/libcxx/include/__iterator/advance.h
@@ -29,6 +29,41 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
+template <class _InputIter>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void
+__advance(_InputIter& __i, typename iterator_traits<_InputIter>::
diff erence_type __n, input_iterator_tag) {
+ for (; __n > 0; --__n)
+ ++__i;
+}
+
+template <class _BiDirIter>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void
+__advance(_BiDirIter& __i, typename iterator_traits<_BiDirIter>::
diff erence_type __n, bidirectional_iterator_tag) {
+ if (__n >= 0)
+ for (; __n > 0; --__n)
+ ++__i;
+ else
+ for (; __n < 0; ++__n)
+ --__i;
+}
+
+template <class _RandIter>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void
+__advance(_RandIter& __i, typename iterator_traits<_RandIter>::
diff erence_type __n, random_access_iterator_tag) {
+ __i += __n;
+}
+
+template <
+ class _InputIter, class _Distance,
+ class = typename enable_if<is_integral<decltype(_VSTD::__convert_to_integral(declval<_Distance>()))>::value>::type>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void advance(_InputIter& __i, _Distance __orig_n) {
+ typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
+ _IntegralSize __n = __orig_n;
+ _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
+ "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
+ _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
+}
+
#if !defined(_LIBCPP_HAS_NO_RANGES)
namespace ranges {
diff --git a/libcxx/include/__iterator/next.h b/libcxx/include/__iterator/next.h
index ec51ab330273..57cd5bab09f3 100644
--- a/libcxx/include/__iterator/next.h
+++ b/libcxx/include/__iterator/next.h
@@ -25,6 +25,17 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
+template <class _InputIter>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+ typename enable_if<__is_cpp17_input_iterator<_InputIter>::value, _InputIter>::type
+ next(_InputIter __x, typename iterator_traits<_InputIter>::
diff erence_type __n = 1) {
+ _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
+ "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
+
+ _VSTD::advance(__x, __n);
+ return __x;
+}
+
#if !defined(_LIBCPP_HAS_NO_RANGES)
namespace ranges {
diff --git a/libcxx/include/__iterator/prev.h b/libcxx/include/__iterator/prev.h
index a6d2f596cb73..3a32f368cb07 100644
--- a/libcxx/include/__iterator/prev.h
+++ b/libcxx/include/__iterator/prev.h
@@ -25,6 +25,16 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
+template <class _InputIter>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+ typename enable_if<__is_cpp17_input_iterator<_InputIter>::value, _InputIter>::type
+ prev(_InputIter __x, typename iterator_traits<_InputIter>::
diff erence_type __n = 1) {
+ _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
+ "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
+ _VSTD::advance(__x, -__n);
+ return __x;
+}
+
#if !defined(_LIBCPP_HAS_NO_RANGES)
namespace ranges {
diff --git a/libcxx/include/iterator b/libcxx/include/iterator
index caa36733d659..364c74325b18 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -589,48 +589,6 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator
typedef _Category iterator_category;
};
-template <class _InputIter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-void __advance(_InputIter& __i,
- typename iterator_traits<_InputIter>::
diff erence_type __n, input_iterator_tag)
-{
- for (; __n > 0; --__n)
- ++__i;
-}
-
-template <class _BiDirIter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-void __advance(_BiDirIter& __i,
- typename iterator_traits<_BiDirIter>::
diff erence_type __n, bidirectional_iterator_tag)
-{
- if (__n >= 0)
- for (; __n > 0; --__n)
- ++__i;
- else
- for (; __n < 0; ++__n)
- --__i;
-}
-
-template <class _RandIter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-void __advance(_RandIter& __i,
- typename iterator_traits<_RandIter>::
diff erence_type __n, random_access_iterator_tag)
-{
- __i += __n;
-}
-
-template <class _InputIter, class _Distance,
- class = typename enable_if<is_integral<decltype(_VSTD::__convert_to_integral(declval<_Distance>()))>::value>::type>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-void advance(_InputIter& __i, _Distance __orig_n)
-{
- typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
- _IntegralSize __n = __orig_n;
- _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
- "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
- _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
-}
-
template <class _InputIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
typename iterator_traits<_InputIter>::
diff erence_type
@@ -658,40 +616,6 @@ distance(_InputIter __first, _InputIter __last)
return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
}
-template <class _InputIter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-typename enable_if
-<
- __is_cpp17_input_iterator<_InputIter>::value,
- _InputIter
->::type
-next(_InputIter __x,
- typename iterator_traits<_InputIter>::
diff erence_type __n = 1)
-{
- _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
- "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
-
- _VSTD::advance(__x, __n);
- return __x;
-}
-
-template <class _InputIter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-typename enable_if
-<
- __is_cpp17_input_iterator<_InputIter>::value,
- _InputIter
->::type
-prev(_InputIter __x,
- typename iterator_traits<_InputIter>::
diff erence_type __n = 1)
-{
- _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
- "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
- _VSTD::advance(__x, -__n);
- return __x;
-}
-
-
template <class _Tp, class = void>
struct __is_stashing_iterator : false_type {};
More information about the libcxx-commits
mailing list