kumi v3.1.0
Exquisite Epidote
 
Loading...
Searching...
No Matches

◆ count_if()

template<typename Pred , typename T >
constexpr std::size_t kumi::count_if ( T const &  ts,
Pred  p 
)
constexprnoexcept

Counts the number of elements of t satisfying predicates p.

Parameters
tsValue to process
pUnary predicate. p must return a value convertible to bool for every element of t.
Returns
Number of elements satisfying the condition.

Example:

#include <kumi/tuple.hpp>
#include <iostream>
#include <type_traits>
int main()
{
auto t = kumi::tuple{1, 2., 3.f, 'z'};
std::cout << std::boolalpha
<< kumi::count_if( t, kumi::predicate<std::is_floating_point>() ) << "\n";
std::cout << std::boolalpha
<< kumi::count_if( 2.3, kumi::predicate<std::is_floating_point>() ) << "\n";
}
constexpr std::size_t count_if(T const &ts, Pred p) noexcept
Counts the number of elements of t satisfying predicates p.
Definition: predicates.hpp:133
Fixed-size collection of heterogeneous values.
Definition: tuple.hpp:35