Skip to content

Commit ed3291e

Browse files
Implement completion signatures and add bulk test with additional tests
1 parent e713f88 commit ed3291e

File tree

3 files changed

+101
-23
lines changed

3 files changed

+101
-23
lines changed

include/beman/execution/detail/bulk.hpp

+55-23
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
// include/beman/execution/detail/bulk.hpp -*-C++-*-
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4-
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_SPLIT
5-
#define INCLUDED_BEMAN_EXECUTION_DETAIL_SPLIT
6-
7-
#include "beman/execution/detail/basic_sender.hpp"
8-
#include "beman/execution/detail/callable.hpp"
9-
#include "beman/execution/detail/completion_signatures_for.hpp"
10-
#include "beman/execution/detail/get_domain_early.hpp"
11-
#include "beman/execution/detail/make_sender.hpp"
12-
#include "beman/execution/detail/movable_value.hpp"
13-
#include "beman/execution/detail/product_type.hpp"
14-
#include "beman/execution/detail/sender.hpp"
15-
#include "beman/execution/detail/set_error.hpp"
16-
#include "beman/execution/detail/transform_sender.hpp"
4+
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_BULK
5+
#define INCLUDED_BEMAN_EXECUTION_DETAIL_BULK
6+
7+
#include "beman/execution/detail/error_types_of_t.hpp"
8+
#include "beman/execution/detail/meta_combine.hpp"
9+
#include "beman/execution/detail/meta_unique.hpp"
10+
#include "beman/execution/detail/set_stopped.hpp"
11+
#include "beman/execution/detail/value_types_of_t.hpp"
12+
#include <beman/execution/detail/basic_sender.hpp>
13+
#include <beman/execution/detail/completion_signatures.hpp>
14+
#include <beman/execution/detail/completion_signatures_for.hpp>
15+
#include <beman/execution/detail/get_domain_early.hpp>
16+
#include <beman/execution/detail/make_sender.hpp>
17+
#include <beman/execution/detail/movable_value.hpp>
18+
#include <beman/execution/detail/product_type.hpp>
19+
#include <beman/execution/detail/sender.hpp>
20+
#include <beman/execution/detail/set_error.hpp>
21+
#include <beman/execution/detail/transform_sender.hpp>
1722
#include <beman/execution/detail/default_impls.hpp>
1823
#include <beman/execution/detail/impls_for.hpp>
1924
#include <beman/execution/detail/set_value.hpp>
@@ -23,16 +28,13 @@
2328
#include <type_traits>
2429
#include <utility>
2530

31+
32+
#include <beman/execution/detail/suppress_push.hpp>
2633
namespace beman::execution::detail {
2734

2835
struct bulk_t {
2936

30-
/*
3137

32-
decltype((sndr)) does not satisfy sender, or
33-
Shape does not satisfy integral, or
34-
decltype((f)) does not satisfy movable-value,
35-
*/
3638
template <class Sender, class Shape, class f>
3739
requires(::beman::execution::sender<Sender> && std::is_integral_v<Shape> &&
3840
::beman::execution::detail::movable_value<f>)
@@ -53,9 +55,9 @@ struct impls_for<bulk_t> : ::beman::execution::detail::default_impls {
5355
static constexpr auto complete = []<class Index, class State, class Rcvr, class Tag, class... Args>(
5456
Index, State& state, Rcvr& rcvr, Tag, Args&&... args) noexcept -> void
5557
requires(not::std::same_as<Tag, set_value_t> ||
56-
::beman::execution::detail::callable<
57-
Tag,
58-
Args...> /* expression f(auto(shape), args...) is well-formed. dont know if this is ok */)
58+
requires(State& s, Args&&... a) {
59+
(s.template get<1>())(s.template get<0>(), ::std::forward<Args>(a)...);
60+
})
5961
{
6062
if constexpr (std::same_as<Tag, set_value_t>) {
6163
auto& [shape, f] = state;
@@ -81,13 +83,43 @@ struct impls_for<bulk_t> : ::beman::execution::detail::default_impls {
8183
};
8284

8385
template <class Shape, class f, class Sender, class Env>
84-
struct completion_signatures_for<
86+
struct completion_signatures_for_impl<
8587
::beman::execution::detail::
8688
basic_sender<::beman::execution::detail::bulk_t, ::beman::execution::detail::product_type<Shape, f>, Sender>,
87-
Env> {};
89+
Env> {
90+
91+
// Creates a completion signature for set_value_t`
92+
template <class... Args>
93+
using make_value_completions =
94+
::beman::execution::completion_signatures<::beman::execution::set_value_t(const std::decay_t<Args>&...)>;
95+
96+
// Creates a completion signature for set_error_t
97+
template <class... Args>
98+
using make_error_completions =
99+
::beman::execution::completion_signatures<::beman::execution::set_error_t(const std::decay_t<Args>&)...>;
100+
101+
// Retrieves the value completion signatures from the Sender using Env,
102+
// then applies `make_value_completions` to format them and merges all signatures.
103+
using value_completions = ::beman::execution::
104+
value_types_of_t<Sender, Env, make_value_completions, ::beman::execution::detail::meta::combine>;
105+
106+
// Retrieves the error completion signatures from the Sender using Env,
107+
// then applies make_error_completions to format them.
108+
using error_completions = ::beman::execution::error_types_of_t<Sender, Env, make_error_completions>;
109+
110+
using fixed_completions =
111+
::beman::execution::completion_signatures<::beman::execution::set_stopped_t(),
112+
::beman::execution::set_error_t(std::exception_ptr)>;
113+
114+
115+
using type = ::beman::execution::detail::meta::unique<
116+
::beman::execution::detail::meta::combine<fixed_completions, value_completions, error_completions>>;
117+
};
88118

89119
} // namespace beman::execution::detail
90120

121+
#include <beman/execution/detail/suppress_pop.hpp>
122+
91123
namespace beman::execution {
92124

93125
using ::beman::execution::detail::bulk_t;

tests/beman/execution/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ list(
5757
exec-when-all.test
5858
exec-with-awaitable-senders.test
5959
execution-queryable-concept.test
60+
exec-bulk.test
6061
execution-syn.test
6162
forward-like.test
6263
function-objects.test
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// src/beman/execution/tests/exec-bulk.test.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include "beman/execution/detail/sync_wait.hpp"
5+
#include <cstdlib>
6+
#include <test/execution.hpp>
7+
#include <beman/execution/detail/bulk.hpp>
8+
#include <beman/execution/detail/just.hpp>
9+
10+
11+
12+
13+
auto test_bulk(){
14+
auto b0 = test_std::bulk(test_std::just(), 1, [](int) {});
15+
16+
static_assert(test_std::sender<decltype(b0)>);
17+
18+
int counter = 0;
19+
20+
auto b1 = test_std::bulk(test_std::just(), 5, [&](int i) {
21+
counter += i;
22+
});
23+
24+
static_assert(test_std::sender<decltype(b1)>);
25+
test_std::sync_wait(b1);
26+
ASSERT(counter == 10);
27+
28+
}
29+
30+
TEST(exec_bulk){
31+
32+
33+
try {
34+
35+
test_bulk();
36+
37+
} catch (...) {
38+
39+
ASSERT(nullptr == "the bulk tests shouldn't throw");
40+
}
41+
42+
return EXIT_SUCCESS;
43+
44+
}
45+

0 commit comments

Comments
 (0)