CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Count.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
17
18namespace CeresEngine {
19
21 class CountAlgorithmFunctor : public ValueCompareAlgorithmFunctor<CountAlgorithmFunctor> {
23
33 template<class I, class S, class T>
34 requires(
35 // clang-format off
36 traits::is_input_iterator_v<I> &&
37 traits::is_sentinel_for_v<S, I> &&
38 traits::is_indirectly_binary_invocable_v<std::equal_to<>, T*, I>
39 // clang-format on
40 ) static constexpr traits::iter_difference_t<I> run(I first, S last, const T& v) {
42 for(; first != last; ++first) {
43 if(*first == v) {
44 ret++;
45 }
46 }
47 return ret;
48 }
49
63 template<class E, class P, class I, class S, class T>
64 requires(
65 // clang-format off
66 traits::is_executor_v<E> &&
67 traits::is_partitioner_v<P, I, S> &&
68 traits::is_input_iterator_v<I> &&
69 traits::is_sentinel_for_v<S, I> &&
70 traits::is_indirectly_binary_invocable_v<std::equal_to<>, T *, I>
71 // clang-format on
72 ) static Async<traits::iter_difference_t<I>> run(const E& executor, P p, I first, S last, const T& v) {
73 if constexpr(traits::is_inline_executor_v<E>) {
74 co_return run(first, last, v);
75 } else {
76 co_return co_await CountIfAlgorithmFunctor::Graph<E, I>(executor).launch(p, first, last, [&v](const auto& element) { return element == v; });
77 }
78 }
79 };
80
82 inline constexpr CountAlgorithmFunctor count;
83
84} // namespace CeresEngine
A partitioner is a light callable object that takes a pair of iterators and returns the middle of the...
Identify traits for algorithms, like we do for other types.
Functor representing the overloads for the count function.
Definition Count.hpp:21
static constexpr traits::iter_difference_t< I > run(I first, S last, const T &v)
Complete overload of the count algorithm.
Definition Count.hpp:40
static Async< traits::iter_difference_t< I > > run(const E &executor, P p, I first, S last, const T &v)
Complete overload of the count algorithm.
Definition Count.hpp:72
Async< traits::iter_difference_t< I > > launch(P p, I first, S last, Fun f)
Definition CountIf.hpp:33
Value-compare algorithm overloads.
Definition ValueCompareAlgorithm.hpp:32
typename iter_difference< T >::type iter_difference_t
A C++17 type trait equivalent to the C++20 iter_difference concept.
Definition iter_difference.hpp:85
Definition Application.hpp:19
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
constexpr CountAlgorithmFunctor count
Returns the number of elements matching an element.
Definition Count.hpp:82
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25