Warning: This file is not a C or C++ file. It does not have highlighting.
| 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___ALGORITHM_FOR_EACH_N_H |
| 11 | #define _LIBCPP___ALGORITHM_FOR_EACH_N_H |
| 12 | |
| 13 | #include <__algorithm/for_each.h> |
| 14 | #include <__algorithm/for_each_n_segment.h> |
| 15 | #include <__config> |
| 16 | #include <__iterator/iterator_traits.h> |
| 17 | #include <__iterator/segmented_iterator.h> |
| 18 | #include <__type_traits/disjunction.h> |
| 19 | #include <__type_traits/enable_if.h> |
| 20 | #include <__type_traits/negation.h> |
| 21 | #include <__utility/convert_to_integral.h> |
| 22 | #include <__utility/move.h> |
| 23 | |
| 24 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 25 | # pragma GCC system_header |
| 26 | #endif |
| 27 | |
| 28 | _LIBCPP_PUSH_MACROS |
| 29 | #include <__undef_macros> |
| 30 | |
| 31 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 32 | |
| 33 | template <class _InputIterator, |
| 34 | class _Size, |
| 35 | class _Func, |
| 36 | __enable_if_t<!__has_random_access_iterator_category<_InputIterator>::value && |
| 37 | _Or< _Not<__is_segmented_iterator<_InputIterator> >, |
| 38 | _Not<__has_random_access_local_iterator<_InputIterator> > >::value, |
| 39 | int> = 0> |
| 40 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator |
| 41 | __for_each_n(_InputIterator __first, _Size __orig_n, _Func& __f) { |
| 42 | typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize; |
| 43 | _IntegralSize __n = __orig_n; |
| 44 | while (__n > 0) { |
| 45 | __f(*__first); |
| 46 | ++__first; |
| 47 | --__n; |
| 48 | } |
| 49 | return std::move(__first); |
| 50 | } |
| 51 | |
| 52 | template <class _RandIter, |
| 53 | class _Size, |
| 54 | class _Func, |
| 55 | __enable_if_t<__has_random_access_iterator_category<_RandIter>::value, int> = 0> |
| 56 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandIter |
| 57 | __for_each_n(_RandIter __first, _Size __orig_n, _Func& __f) { |
| 58 | typename std::iterator_traits<_RandIter>::difference_type __n = __orig_n; |
| 59 | auto __last = __first + __n; |
| 60 | std::__for_each(__first, __last, __f); |
| 61 | return std::move(__last); |
| 62 | } |
| 63 | |
| 64 | #ifndef _LIBCPP_CXX03_LANG |
| 65 | template <class _SegmentedIterator, |
| 66 | class _Size, |
| 67 | class _Func, |
| 68 | __enable_if_t<!__has_random_access_iterator_category<_SegmentedIterator>::value && |
| 69 | __is_segmented_iterator<_SegmentedIterator>::value && |
| 70 | __has_random_access_iterator_category< |
| 71 | typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator>::value, |
| 72 | int> = 0> |
| 73 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _SegmentedIterator |
| 74 | __for_each_n(_SegmentedIterator __first, _Size __orig_n, _Func& __f) { |
| 75 | using __local_iterator_t = typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator; |
| 76 | return std::__for_each_n_segment(__first, __orig_n, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) { |
| 77 | std::__for_each(__lfirst, __llast, __f); |
| 78 | }); |
| 79 | } |
| 80 | #endif // !_LIBCPP_CXX03_LANG |
| 81 | |
| 82 | #if _LIBCPP_STD_VER >= 17 |
| 83 | |
| 84 | template <class _InputIterator, class _Size, class _Function> |
| 85 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator |
| 86 | for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) { |
| 87 | return std::__for_each_n(__first, __orig_n, __f); |
| 88 | } |
| 89 | |
| 90 | #endif // _LIBCPP_STD_VER >= 17 |
| 91 | |
| 92 | _LIBCPP_END_NAMESPACE_STD |
| 93 | |
| 94 | _LIBCPP_POP_MACROS |
| 95 | |
| 96 | #endif // _LIBCPP___ALGORITHM_FOR_EACH_N_H |
| 97 |
Warning: This file is not a C or C++ file. It does not have highlighting.
