[libcxx-commits] [libcxx] [libcxx] Added segmented iterator for count_if (PR #105888)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 30 13:08:53 PDT 2024
================
@@ -10,26 +10,52 @@
#ifndef _LIBCPP___ALGORITHM_COUNT_IF_H
#define _LIBCPP___ALGORITHM_COUNT_IF_H
+#include <__algorithm/for_each.h>
#include <__config>
#include <__iterator/iterator_traits.h>
+#include <__iterator/segmented_iterator.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
-template <class _InputIterator, class _Predicate>
+template <class _InputIterator,
+ class _Predicate,
+ __enable_if_t<!__is_segmented_iterator<_InputIterator>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-typename iterator_traits<_InputIterator>::difference_type
-count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
+ typename iterator_traits<_InputIterator>::difference_type
+ __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
typename iterator_traits<_InputIterator>::difference_type __r(0);
for (; __first != __last; ++__first)
if (__pred(*__first))
++__r;
return __r;
}
+template <class _SegmentedIterator,
----------------
adeel10x wrote:
Thanks for the feedback. Are you suggesting that instead of having separate function templates for Input and Segmented Iterators, I should have a single one that just calls `for_each` internally?
https://github.com/llvm/llvm-project/pull/105888
More information about the libcxx-commits
mailing list