CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
AllOf.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
16
17namespace CeresEngine {
18
20 class AllOfAlgorithmFunctor : public UnaryAlgorithmFunctor<AllOfAlgorithmFunctor> {
22
24 template<class Executor> class Graph {
25 private:
26 const Executor& mExecutor;
27
28 public:
29 explicit Graph(const Executor& executor) : mExecutor(executor) {}
30
31 template<class P, class I, class S, class Fun> Async<bool> launch(P p, I first, S last, Fun f) {
32 auto middle = p(first, last);
33 const bool isTooSmall = middle == last;
34 const bool isNotParallelize = traits::is_forward_iterator_v<I>;
36 return with(mExecutor, [first, last, f]() { return run(first, last, f); });
37 }
38
39 return when_all(
40 // Create task that launches tasks for rhs: [middle, last]
41 launch(p, middle, last, f),
42
43 // Launch tasks for lhs: [first, middle]
44 launch(p, first, middle, f))
45 .then(std::logical_and{});
46 }
47 };
48
57 template<class I, class S, class Fun>
58 requires(
59 // clang-format off
60 traits::is_input_iterator_v<I> &&
61 traits::is_sentinel_for_v<S, I> &&
62 traits::is_indirectly_unary_invocable_v<Fun, I> &&
63 std::is_copy_constructible_v<Fun>
64 // clang-format on
65 ) static constexpr bool run(I first, S last, Fun f) {
66 return std::all_of(first, last, std::move(f));
67 }
68
81 template<class E, class P, class I, class S, class Fun>
82 requires(
83 // clang-format off
84 traits::is_executor_v<E> &&
85 traits::is_partitioner_v<P, I, S> &&
86 traits::is_input_iterator_v<I> &&
87 traits::is_sentinel_for_v<S, I> &&
88 traits::is_indirectly_unary_invocable_v<Fun, I> &&
89 std::is_copy_constructible_v<Fun>
90 // clang-format on
91 ) static Async<bool> run(const E& executor, P p, I first, S last, Fun f) {
92 if constexpr(traits::is_inline_executor_v<E>) {
93 co_return run(first, last, std::move(f));
94 } else {
95 co_return co_await Graph<E>(executor).launch(p, first, last, std::move(f));
96 }
97 }
98 };
99
102
103} // 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...
const Executor & mExecutor
Definition AllOf.hpp:26
Graph(const Executor &executor)
Definition AllOf.hpp:29
Async< bool > launch(P p, I first, S last, Fun f)
Definition AllOf.hpp:31
Functor representing the overloads for the all_of function.
Definition AllOf.hpp:20
static Async< bool > run(const E &executor, P p, I first, S last, Fun f)
Complete overload of the all_of algorithm.
Definition AllOf.hpp:91
static constexpr bool run(I first, S last, Fun f)
Complete overload of the all_of algorithm.
Definition AllOf.hpp:65
Overloads for unary invoke algorithms.
Definition UnaryAlgorithm.hpp:34
Definition Application.hpp:19
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
constexpr AllOfAlgorithmFunctor all_of
Checks if a predicate is true for all the elements in a range.
Definition AllOf.hpp:101