Skip to content

Commit 9e789a3

Browse files
Align Bulk Adaptor Sender completion signatures with base sender
1 parent 1ca12ce commit 9e789a3

File tree

2 files changed

+102
-30
lines changed

2 files changed

+102
-30
lines changed

include/beman/execution/detail/bulk.hpp

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_BULK
55
#define INCLUDED_BEMAN_EXECUTION_DETAIL_BULK
66

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"
7+
#include "beman/execution/detail/callable.hpp"
8+
#include "beman/execution/detail/get_completion_signatures.hpp"
9+
#include "beman/execution/detail/nothrow_callable.hpp"
1210
#include <beman/execution/detail/basic_sender.hpp>
1311
#include <beman/execution/detail/completion_signatures.hpp>
1412
#include <beman/execution/detail/completion_signatures_for.hpp>
@@ -80,37 +78,56 @@ struct impls_for<bulk_t> : ::beman::execution::detail::default_impls {
8078
};
8179
};
8280

83-
template <class Shape, class f, class Sender, class Env>
84-
struct completion_signatures_for_impl<
85-
::beman::execution::detail::
86-
basic_sender<::beman::execution::detail::bulk_t, ::beman::execution::detail::product_type<Shape, f>, Sender>,
87-
Env> {
81+
template <typename T>
82+
struct print_type;
83+
84+
// Specialization to trigger a compile-time error and print the type
85+
template <typename T>
86+
struct print_type {
87+
static_assert(sizeof(T) == 0, "Debugging type...");
88+
};
89+
90+
/*template <typename, typename, typename, typename,typename>
91+
struct fixed_completions_helper;
92+
template <typename F, typename Shape,typename Sender,typename Env, typename... Args>
93+
struct fixed_completions_helper<F, Shape,Sender, Env, completion_signatures<Args...>> {
94+
using completions = ::beman::execution::value_types_of_t<Sender,Env>;
95+
static_assert(std::is_invocable_v<F, completions>,"Error: The function is not callable with the given arguments.");
96+
using type = std::conditional_t<::beman::execution::detail::nothrow_callable<F, Args ...>,
97+
completion_signatures<Args...>,
98+
completion_signatures<Args..., set_error_t(std::exception_ptr)>>;
99+
};
88100
89-
// Creates a completion signature for set_value_t
90-
template <class... Args>
91-
using make_value_completions =
92-
::beman::execution::completion_signatures<::beman::execution::set_value_t(const std::decay_t<Args>&...)>;
101+
template <typename F, typename Shape, typename Sender , typename Env, typename completions>
102+
using fixed_completions = typename fixed_completions_helper<F, Shape, Sender , Env, completions>::type;*/
93103

94-
// Creates a completion signature for set_error_t
95-
template <class... Args>
96-
using make_error_completions =
97-
::beman::execution::completion_signatures<::beman::execution::set_error_t(const std::decay_t<Args>&)...>;
98104

99-
// Retrieves the value completion signatures from the Sender using Env,
100-
// then applies make_value_completions to format them and merges all signatures.
101-
using value_completions = ::beman::execution::
102-
value_types_of_t<Sender, Env, make_value_completions, ::beman::execution::detail::meta::combine>;
103105

104-
// Retrieves the error completion signatures from the Sender using Env,
105-
// then applies make_error_completions to format them.
106-
using error_completions = ::beman::execution::error_types_of_t<Sender, Env, make_error_completions>;
107106

108-
using fixed_completions =
109-
::beman::execution::completion_signatures<::beman::execution::set_stopped_t(),
110-
::beman::execution::set_error_t(std::exception_ptr)>;
107+
template <typename, typename, typename>
108+
struct fixed_completions_helper;
109+
110+
template <typename F, typename Shape, typename... Args>
111+
struct fixed_completions_helper<F, Shape, completion_signatures<Args...>> {
112+
//static_assert(std::is_invocable_v<F, Shape, Args...>,"Error: The function is not callable with the given arguments.");
113+
using type = std::conditional_t<::beman::execution::detail::nothrow_callable<F, Args ...>,
114+
completion_signatures<Args...>,
115+
completion_signatures<Args..., set_error_t(std::exception_ptr)>>;
116+
};
117+
118+
template <typename F, typename Shape, typename Completions>
119+
using fixed_completions = typename fixed_completions_helper<F, Shape, Completions>::type;
120+
121+
template <class Shape, class F, class Sender, class Env>
122+
struct completion_signatures_for_impl<
123+
::beman::execution::detail::
124+
basic_sender<::beman::execution::detail::bulk_t, ::beman::execution::detail::product_type<Shape, F>, Sender>,
125+
Env> {
126+
111127

112-
using type = ::beman::execution::detail::meta::unique<
113-
::beman::execution::detail::meta::combine<fixed_completions, value_completions, error_completions>>;
128+
using completions = decltype(get_completion_signatures(std::declval<Sender>(), std::declval<Env>()));
129+
using type = fixed_completions<F, Shape, completions>;
130+
//print_type<type> debug;
114131
};
115132

116133
} // namespace beman::execution::detail

tests/beman/execution/exec-bulk.test.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,86 @@
11
// src/beman/execution/tests/exec-bulk.test.cpp -*-C++-*-
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4+
#include "beman/execution/detail/get_completion_signatures.hpp"
5+
#include "beman/execution/detail/get_env.hpp"
46
#include "beman/execution/detail/sync_wait.hpp"
57
#include <cstdlib>
68
#include <test/execution.hpp>
79
#include <beman/execution/detail/bulk.hpp>
810
#include <beman/execution/detail/just.hpp>
11+
#include <vector>
912

1013
auto test_bulk() {
1114
auto b0 = test_std::bulk(test_std::just(), 1, [](int) {});
1215

1316
static_assert(test_std::sender<decltype(b0)>);
17+
auto b0_env = test_std::get_env(b0);
18+
auto b0_completions = test_std::get_completion_signatures(b0, b0_env);
19+
static_assert(
20+
std::is_same_v<decltype(b0_completions),
21+
beman::execution::completion_signatures<beman::execution::set_value_t(),
22+
beman::execution::set_error_t(std::exception_ptr)> >,
23+
"Completion signatures do not match!");
1424

1525
int counter = 0;
1626

1727
auto b1 = test_std::bulk(test_std::just(), 5, [&](int i) { counter += i; });
1828

1929
static_assert(test_std::sender<decltype(b1)>);
30+
auto b1_env = test_std::get_env(b0);
31+
auto b1_completions = test_std::get_completion_signatures(b1, b1_env);
32+
static_assert(
33+
std::is_same_v<decltype(b1_completions),
34+
beman::execution::completion_signatures<beman::execution::set_value_t(),
35+
beman::execution::set_error_t(std::exception_ptr)> >,
36+
"Completion signatures do not match!");
2037
test_std::sync_wait(b1);
2138
ASSERT(counter == 10);
39+
40+
std::vector<int> a{1, 2, 3, 4, 5, 6, 7, 8};
41+
std::vector<int> b{9, 10, 11, 13, 14, 15, 16, 17};
42+
43+
std::vector<int> results(a.size(), 0);
44+
45+
auto b2 = test_std::bulk(test_std::just(a), a.size(), [&](std::size_t index, const std::vector<int>& vec) {
46+
results[index] = vec[index] * b[index];
47+
});
48+
static_assert(test_std::sender<decltype(b2)>);
49+
auto b2_env = test_std::get_env(b2);
50+
auto b2_completions = test_std::get_completion_signatures(b2, b2_env);
51+
static_assert(
52+
std::is_same_v<decltype(b2_completions),
53+
beman::execution::completion_signatures<beman::execution::set_value_t(std::vector<int>),
54+
beman::execution::set_error_t(std::exception_ptr)> >,
55+
"Completion signatures do not match!");
56+
test_std::sync_wait(b2);
57+
58+
// Expected results: element-wise multiplication of a and b
59+
std::vector<int> expected{9, 20, 33, 52, 70, 90, 112, 136};
60+
61+
62+
for (size_t i = 0; i < results.size(); ++i) {
63+
ASSERT(results[i] == expected[i]);
64+
}
65+
}
66+
67+
auto test_bulk_noexept() {
68+
auto b0 = test_std::bulk(test_std::just(), 1, [](int) noexcept {});
69+
auto b0_env = test_std::get_env(b0);
70+
auto b0_completions = test_std::get_completion_signatures(b0, b0_env);
71+
/*static_assert(
72+
std::is_same_v<decltype(b0_completions),
73+
beman::execution::completion_signatures<beman::execution::set_value_t()> >,
74+
"Completion signatures do not match!");*/
75+
static_assert(test_std::sender<decltype(b0)>);
2276
}
2377

2478
TEST(exec_bulk) {
2579

2680
try {
2781

2882
test_bulk();
83+
test_bulk_noexept();
2984

3085
} catch (...) {
3186

0 commit comments

Comments
 (0)