CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
AnyOf.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
10#include "UnaryAlgorithm.hpp"
11
14
15namespace CeresEngine {
16
18 class AnyOfAlgorithmFunctor : public UnaryAlgorithmFunctor<AnyOfAlgorithmFunctor> {
20
22 template<class Executor> class Graph {
23 private:
24 const Executor& mExecutor;
25
26 public:
27 explicit Graph(const Executor& executor) : mExecutor(executor) {}
28
29 template<class P, class I, class S, class Fun> Async<bool> launch(P p, I first, S last, Fun f) {
30 auto middle = p(first, last);
31 const bool isTooSmall = middle == last;
32 constexpr bool isNotParallelize = traits::is_forward_iterator_v<I>;
34 return with(mExecutor, [first, last, f]() { return run(first, last, f); });
35 }
36
37 return when_all(
38 // Create task that launches tasks for rhs: [middle, last]
39 launch(p, middle, last, f),
40
41 // Launch tasks for lhs: [first, middle]
42 launch(p, first, middle, f))
43 .then(std::logical_or{});
44 }
45 };
46
55 template<class I, class S, class Fun>
56 requires(
57 // clang-format off
58 traits::is_input_iterator_v<I> &&
59 traits::is_sentinel_for_v<S, I> &&
60 traits::is_indirectly_unary_invocable_v<Fun, I> &&
61 std::is_copy_constructible_v<Fun>
62 // clang-format on
63 ) static constexpr bool run(I first, S last, Fun f) {
64 return std::any_of(first, last, std::move(f));
65 }
66
79 template<class E, class P, class I, class S, class Fun>
80 requires(
81 // clang-format off
82 traits::is_executor_v<E> &&
83 traits::is_partitioner_v<P, I, S> &&
84 traits::is_input_iterator_v<I> &&
85 traits::is_sentinel_for_v<S, I> &&
86 traits::is_indirectly_unary_invocable_v<Fun, I> &&
87 std::is_copy_constructible_v<Fun>
88 // clang-format on
89 ) static Async<bool> run(const E& executor, P p, I first, S last, Fun f) {
90 if constexpr(traits::is_inline_executor_v<E>) {
91 co_return run(first, last, std::move(f));
92 } else {
93 co_return co_await Graph<E>(executor).launch(p, first, last, std::move(f));
94 }
95 }
96 };
97
99 inline constexpr AnyOfAlgorithmFunctor any_of;
100
101} // 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 The traits help us generate auxiliary algo...
Graph(const Executor &executor)
Definition AnyOf.hpp:27
Async< bool > launch(P p, I first, S last, Fun f)
Definition AnyOf.hpp:29
const Executor & mExecutor
Definition AnyOf.hpp:24
Functor representing the overloads for the any_of function.
Definition AnyOf.hpp:18
static Async< bool > run(const E &executor, P p, I first, S last, Fun f)
Complete overload of the any_of algorithm.
Definition AnyOf.hpp:89
static constexpr bool run(I first, S last, Fun f)
Complete overload of the any_of algorithm.
Definition AnyOf.hpp:63
Overloads for unary invoke algorithms.
Definition UnaryAlgorithm.hpp:34
Definition Application.hpp:19
constexpr AnyOfAlgorithmFunctor any_of
Checks if a predicate is true for any of the elements in a range.
Definition AnyOf.hpp:99
auto with(Executor executor)
Definition ExecutionContext.hpp:546
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25