Skip to content

Commit

Permalink
Allow non-default constructible types in static_thread_pool bulk cust…
Browse files Browse the repository at this point in the history
…omization
  • Loading branch information
msimberg authored and ericniebler committed Nov 11, 2024
1 parent c1508b1 commit 15dcdbc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
10 changes: 8 additions & 2 deletions include/exec/static_thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ namespace exec {
CvrefSender,
env_of_t<Receiver>,
__q<__decayed_std_tuple>,
__q<__std_variant>>;
__q<__nullable_std_variant>>;

variant_t data_;
static_thread_pool_& pool_;
Expand All @@ -1217,7 +1217,13 @@ namespace exec {
template <class F>
void apply(F f) {
std::visit(
[&](auto& tupl) -> void { std::apply([&](auto&... args) -> void { f(args...); }, tupl); },
[&](auto& tupl) -> void {
if constexpr (same_as<__decay_t<decltype(tupl)>, std::monostate>) {
std::terminate();
} else {
std::apply([&](auto&... args) -> void { f(args...); }, tupl);
}
},
data_);
}

Expand Down
15 changes: 15 additions & 0 deletions test/stdexec/algos/adaptors/test_bulk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <stdexec/execution.hpp>
#include <test_common/schedulers.hpp>
#include <test_common/receivers.hpp>
#include <test_common/senders.hpp>
#include <test_common/type_helpers.hpp>
#include <exec/static_thread_pool.hpp>

Expand Down Expand Up @@ -337,4 +338,18 @@ namespace {
CHECK(actual != wrong);
}
}

TEST_CASE("default bulk works with non-default constructible types", "[adaptors][bulk]") {
ex::sender auto s = ex::just(non_default_constructible{42}) | ex::bulk(1, [](int, auto&) {});
ex::sync_wait(std::move(s));
}

TEST_CASE("static thread pool works with non-default constructible types", "[adaptors][bulk]") {
exec::static_thread_pool pool{4};
ex::scheduler auto sch = pool.get_scheduler();

ex::sender auto s = ex::just(non_default_constructible{42}) | ex::continues_on(sch)
| ex::bulk(1, [](int, auto&) {});
ex::sync_wait(std::move(s));
}
} // namespace
16 changes: 2 additions & 14 deletions test/stdexec/algos/adaptors/test_schedule_from.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdexec/execution.hpp>
#include <test_common/schedulers.hpp>
#include <test_common/receivers.hpp>
#include <test_common/senders.hpp>
#include <test_common/type_helpers.hpp>
#include <exec/any_sender_of.hpp>
#include <exec/static_thread_pool.hpp>
Expand Down Expand Up @@ -112,19 +113,6 @@ namespace {
REQUIRE(called);
}

struct non_default_constructible {
int x;

non_default_constructible(int x)
: x(x) {
}

friend bool
operator==(non_default_constructible const & lhs, non_default_constructible const & rhs) {
return lhs.x == rhs.x;
}
};

TEST_CASE(
"schedule_from can accept non-default constructible types",
"[adaptors][schedule_from]") {
Expand Down Expand Up @@ -249,4 +237,4 @@ namespace {
auto op = ex::connect(std::move(snd), expect_value_receiver(3));
ex::start(op);
}
} // namespace
} // namespace
13 changes: 13 additions & 0 deletions test/test_common/senders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,17 @@ namespace {
return {self.condition_, std::forward<Receiver>(rcvr)};
}
};

struct non_default_constructible {
int x;

non_default_constructible(int x)
: x(x) {
}

friend bool
operator==(non_default_constructible const & lhs, non_default_constructible const & rhs) {
return lhs.x == rhs.x;
}
};
} // namespace

0 comments on commit 15dcdbc

Please sign in to comment.