Path: blob/main/contrib/llvm-project/libcxx/include/__algorithm/count_if.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___ALGORITHM_COUNT_IF_H10#define _LIBCPP___ALGORITHM_COUNT_IF_H1112#include <__config>13#include <__iterator/iterator_traits.h>1415#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)16# pragma GCC system_header17#endif1819_LIBCPP_BEGIN_NAMESPACE_STD2021template <class _InputIterator, class _Predicate>22_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX2023typename iterator_traits<_InputIterator>::difference_type24count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {25typename iterator_traits<_InputIterator>::difference_type __r(0);26for (; __first != __last; ++__first)27if (__pred(*__first))28++__r;29return __r;30}3132_LIBCPP_END_NAMESPACE_STD3334#endif // _LIBCPP___ALGORITHM_COUNT_IF_H353637