Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ if(NOT MSVC)
issue_affine
cppnow_affinity
cppnow_basic
# FIXME: cppnow_query
cppnow_query
cppnow_result_types
cppnow_return
# FIXME: cppnow_stop_token
cppnow_stop_token
cppnow_with_error
co_await_result
co_await_task
Expand All @@ -57,9 +57,9 @@ if(NOT MSVC)
friendly
hello
issue_frame_allocator
# FIXME: query
query
result_example
# FIXME: stop
stop
)
endif()

Expand Down
7 changes: 3 additions & 4 deletions examples/cppnow_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include <beman/execution.hpp>
#include <iostream>

namespace ex = beman::execution;
namespace exd = beman::execution::detail;
namespace ex = beman::execution;

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -61,6 +60,6 @@ ex::task<void, fancy> with_fancy_env() {
} // namespace

int main() {
ex::sync_wait(exd::write_env(with_env(), exd::make_env(get_value, 17)));
ex::sync_wait(exd::write_env(with_fancy_env(), exd::make_env(get_value, 17)));
ex::sync_wait(ex::write_env(with_env(), ex::detail::make_env(get_value, 17)));
ex::sync_wait(ex::write_env(with_fancy_env(), ex::detail::make_env(get_value, 17)));
}
2 changes: 1 addition & 1 deletion examples/cppnow_stop_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main() {

ex::inplace_stop_source source;
std::thread thread([&] {
ex::sync_wait(ex::detail::write_env(stopping(), ex::detail::make_env(ex::get_stop_token, source.get_token())));
ex::sync_wait(ex::write_env(stopping(), ex::detail::make_env(ex::get_stop_token, source.get_token())));
});

std::this_thread::sleep_for(100ms);
Expand Down
14 changes: 11 additions & 3 deletions examples/into_optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ template <typename... S>
struct multi_sender {
using sender_concept = ex::sender_tag;
using completion_signatures = ex::completion_signatures<S...>;
template <typename...>
static consteval auto get_completion_signatures() {
return completion_signatures{};
}

template <typename Receiver>
auto connect(Receiver&& receiver) const {
Expand Down Expand Up @@ -69,8 +73,12 @@ auto my_into_optional(S&& s) {
int main() {
queue<double> que;
ex::sync_wait([](auto& q) -> ex::task<> {
// auto x = co_await ex::just(true) | into_optional;
[[maybe_unused]] std::optional x = co_await (q.async_pop() | ex::into_optional);
[[maybe_unused]] std::optional y = co_await ex::into_optional(q.async_pop());
static_assert(
std::same_as<void,
decltype(ex::get_completion_signatures<decltype(ex::just(true) | ex::into_optional)>())>);
// auto x = co_await (ex::just(true) | ex::into_optional);
// [[maybe_unused]] std::optional x = co_await (q.async_pop() | ex::into_optional);
// [[maybe_unused]] std::optional y = co_await ex::into_optional(q.async_pop());
co_return;
}(que));
}
4 changes: 2 additions & 2 deletions examples/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ struct context {
};

int main() {
ex::sync_wait(ex::detail::write_env(
ex::sync_wait(ex::write_env(
[]() -> ex::task<void, simple_context> {
auto value(co_await ex::read_env(get_value));
std::cout << "value=" << value << "\n";
}(),
ex::detail::make_env(get_value, 42)));
ex::sync_wait(ex::detail::write_env(
ex::sync_wait(ex::write_env(
[]() -> ex::task<void, context> {
auto value(co_await ex::read_env(get_value));
std::cout << "value=" << value << "\n";
Expand Down
2 changes: 1 addition & 1 deletion examples/stop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main() {
};
};

auto [result] = ex::sync_wait(ex::detail::write_env(
auto [result] = ex::sync_wait(ex::write_env(
[]() -> ex::task<std::uint64_t, context> {
auto token(co_await ex::read_env(ex::get_stop_token));
std::uint64_t count{};
Expand Down
23 changes: 13 additions & 10 deletions include/beman/task/detail/into_optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace beman::task::detail {
inline constexpr struct into_optional_t : beman::execution::sender_adaptor_closure<into_optional_t> {
template <::beman::execution::sender Upstream>
struct sender {
using upstream_t = std::remove_cvref_t<Upstream>;
using sender_concept = ::beman::execution::sender_tag;
using upstream_t = std::remove_cvref_t<Upstream>;
upstream_t upstream;

template <typename...>
Expand Down Expand Up @@ -48,22 +48,25 @@ inline constexpr struct into_optional_t : beman::execution::sender_adaptor_closu
}

template <typename Env>
static auto get_type(Env&&) {
static consteval auto get_type() {
return find_type(
::beman::execution::value_types_of_t<Upstream, std::remove_cvref_t<Env>, type_list, type_list>());
}

template <typename... E, typename... S>
constexpr auto make_signatures(auto&& env, type_list<E...>, type_list<S...>) const {
template <typename Env, typename... E, typename... S>
static consteval auto make_signatures(type_list<E...>, type_list<S...>) {
return ::beman::execution::completion_signatures<::beman::execution::set_value_t(
decltype(this->get_type(env))),
decltype(get_type<Env>())),
::beman::execution::set_error_t(E)...,
S...>();
}
template <typename Env>
auto get_completion_signatures(Env&& env) const {
return make_signatures(
env,
template <typename, typename Env>
static consteval auto get_completion_signatures() {
static_assert(::beman::execution::sender<Upstream>);
static_assert(::beman::execution::sender_in<Upstream>);
static_assert(::beman::execution::sender_in<Upstream, Env>);
return make_signatures<Env>(
::beman::execution::value_types_of_t<Upstream, std::remove_cvref_t<Env>, type_list>{},
::beman::execution::error_types_of_t<Upstream, std::remove_cvref_t<Env>, type_list>{},
std::conditional_t<::beman::execution::sends_stopped<Upstream, std::remove_cvref_t<Env>>,
type_list<::beman::execution::set_stopped_t()>,
Expand All @@ -73,7 +76,7 @@ inline constexpr struct into_optional_t : beman::execution::sender_adaptor_closu
struct make_object {
template <typename... A>
auto operator()(A&&... a) const
-> decltype(get_type(::beman::execution::get_env(std::declval<Receiver>()))) {
-> decltype(get_type<decltype(::beman::execution::get_env(std::declval<Receiver>()))>()) {
if constexpr (sizeof...(A) == 0u)
return {};
else
Expand Down
Loading