Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
count_if.hpp
Go to the documentation of this file.
1
// Copyright 2026, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
#
ifndef
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_COUNT_IF_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_COUNT_IF_HPP_
7
8
#
include
"arene/base/algorithm/detail/functional.hpp"
9
#
include
"arene/base/algorithm/detail/traits.hpp"
10
#
include
"arene/base/constraints.hpp"
11
#
include
"arene/base/type_traits/is_predicate.hpp"
12
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
13
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
14
#
include
"stdlib/include/stdlib_detail/is_convertible.hpp"
15
16
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
17
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
18
19
// IWYU pragma: private, include <algorithm>
20
// IWYU pragma: friend "stdlib_detail/.*"
21
22
namespace
std
{
23
24
// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
25
/// @brief Count the number of elements in a range satisfying a predicate
26
/// @tparam InputIterator The type of the iterators denoting the input range.
27
/// @tparam UnaryPredicate The type of the unary callable that returns a boolean testable value
28
/// @param begin The start of the range
29
/// @param end The end of the range
30
/// @param predicate The unary predicate which returns @c true for the counted elements
31
/// @return The count of elements in the range for which @c predicate returns @c true
32
/// @pre @c InputIterator must satisfy the input iterator requirements.
33
/// @pre @c [begin,end) must be a valid range.
34
/// @pre The expression @c predicate(v) must be convertible to bool for every argument v of type (possibly const) VT,
35
/// where VT is the value type of InputIterator, regardless of value category, and must not modify v.
36
template
<
37
class
InputIterator
,
38
class
UnaryPredicate
,
39
arene
::
base
::
constraints
<
40
enable_if_t
<
arene
::
base
::
is_input_iterator_v
<
InputIterator
>>,
41
enable_if_t
<
arene
::
base
::
is_predicate_v
<
42
UnaryPredicate
&,
43
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
InputIterator
>>>> =
nullptr
>
44
constexpr
auto
count_if
(
InputIterator
begin
,
InputIterator
end
,
UnaryPredicate
predicate
) ->
45
typename
std
::
iterator_traits
<
InputIterator
>::
difference_type
{
46
typename
std
::
iterator_traits
<
InputIterator
>::
difference_type
count
{0};
47
while
(
begin
!=
end
) {
48
if
(
static_cast
<
bool
>(
predicate
(*
begin
))) {
49
++
count
;
50
}
51
// parasoft-begin-suppress AUTOSAR-M5_0_15-a-2 "This is an iterator type, so incrementing is OK"
52
++
begin
;
53
// parasoft-end-suppress AUTOSAR-M5_0_15-a-2
54
}
55
return
count
;
56
}
57
// parasoft-end-suppress AUTOSAR-M3_3_2-a
58
59
}
// namespace std
60
61
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_COUNT_IF_HPP_
std::hash<::arene::base::result< void, E > >::operator()
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition
result.hpp:1827
stdlib
include
stdlib_detail
count_if.hpp
Generated by
1.13.2