CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
NoneOf.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
13
14namespace CeresEngine {
15
17 class NoneOfAlgorithmFunctor : public UnaryAlgorithmFunctor<NoneOfAlgorithmFunctor> {
19
21 template<class Executor> class Graph {
22 private:
23 const Executor& mExecutor;
24
25 public:
26 explicit Graph(const Executor& executor) : mExecutor(executor) {}
27
28 template<class P, class I, class S, class Fun> Async<bool> launch(P p, I first, S last, Fun f) {
29 auto middle = p(first, last);
30 const bool isTooSmall = middle == last;
31 constexpr bool isNotParallelize = traits::is_forward_iterator_v<I>;
33 return with(mExecutor, [first, last, f]() { return run(first, last, f); });
34 }
35
36 return when_all(
37 // Create task that launches tasks for rhs: [middle, last]
38 launch(p, middle, last, f),
39
40 // Launch tasks for lhs: [first, middle]
41 launch(p, first, middle, f))
42 .then(std::logical_and<>{});
43 }
44 };
45
54 template<class I, class S, class Fun>
55 requires(
56 // clang-format off
57 traits::is_input_iterator_v<I> &&
58 traits::is_sentinel_for_v<S, I> &&
59 traits::is_indirectly_unary_invocable_v<Fun, I> &&
60 std::is_copy_constructible_v<Fun>
61 // clang-format on
62 ) static constexpr bool run(I first, S last, Fun p) {
63 return std::none_of(first, last, std::move(p));
64 }
65
78 template<class E, class P, class I, class S, class Fun>
79 requires(
80 // clang-format off
81 traits::is_executor_v<E> &&
82 traits::is_partitioner_v<P, I, S> &&
83 traits::is_input_iterator_v<I> &&
84 traits::is_sentinel_for_v<S, I> &&
85 traits::is_indirectly_unary_invocable_v<Fun, I> &&
86 std::is_copy_constructible_v<Fun>
87 // clang-format on
88 ) static Async<bool> run(const E& executor, P p, I first, S last, Fun f) {
89 if constexpr(traits::is_inline_executor_v<E>) {
90 co_return run(first, last, f);
91 } else {
92 co_return co_await Graph<E>(executor).launch(p, first, last, f);
93 }
94 }
95 };
96
99
100} // 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 NoneOf.hpp:26
Async< bool > launch(P p, I first, S last, Fun f)
Definition NoneOf.hpp:28
const Executor & mExecutor
Definition NoneOf.hpp:23
Functor representing the overloads for the none_of function.
Definition NoneOf.hpp:17
static Async< bool > run(const E &executor, P p, I first, S last, Fun f)
Complete overload of the none_of algorithm.
Definition NoneOf.hpp:88
static constexpr bool run(I first, S last, Fun p)
Complete overload of the none_of algorithm.
Definition NoneOf.hpp:62
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 NoneOfAlgorithmFunctor none_of
Checks if a predicate is true for none of the elements in a range.
Definition NoneOf.hpp:98
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25