Skip to content

Commit

Permalink
Stop accessing P2300 entities through the std:: namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler committed Oct 27, 2022
1 parent c90e3f6 commit a4008ee
Show file tree
Hide file tree
Showing 109 changed files with 975 additions and 979 deletions.
34 changes: 16 additions & 18 deletions examples/algorithms/retry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ using _copy_cvref_t = stdexec::__member_t<From, To>;
template <class From, class To>
concept _decays_to = std::same_as<std::decay_t<From>, To>;

namespace stdex = std::execution;

///////////////////////////////////////////////////////////////////////////////
// retry algorithm:

Expand All @@ -48,7 +46,7 @@ struct _op;
// pass through all customizations except set_error, which retries the operation.
template<class S, class R>
struct _retry_receiver
: stdex::receiver_adaptor<_retry_receiver<S, R>> {
: stdexec::receiver_adaptor<_retry_receiver<S, R>> {
_op<S, R>* o_;

R&& base() && noexcept { return (R&&) o_->r_; }
Expand All @@ -69,24 +67,24 @@ struct _op {
S s_;
R r_;
std::optional<
stdex::connect_result_t<S&, _retry_receiver<S, R>>> o_;
stdexec::connect_result_t<S&, _retry_receiver<S, R>>> o_;

_op(S s, R r): s_((S&&)s), r_((R&&)r), o_{_connect()} {}
_op(_op&&) = delete;

auto _connect() noexcept {
return _conv{[this] {
return stdex::connect(s_, _retry_receiver<S, R>{this});
return stdexec::connect(s_, _retry_receiver<S, R>{this});
}};
}
void _retry() noexcept try {
o_.emplace(_connect()); // potentially throwing
stdex::start(*o_);
stdexec::start(*o_);
} catch(...) {
stdex::set_error((R&&) r_, std::current_exception());
stdexec::set_error((R&&) r_, std::current_exception());
}
friend void tag_invoke(stdex::start_t, _op& o) noexcept {
stdex::start(*o.o_);
friend void tag_invoke(stdexec::start_t, _op& o) noexcept {
stdexec::start(*o.o_);
}
};

Expand All @@ -96,24 +94,24 @@ struct _retry_sender {
explicit _retry_sender(S s) : s_((S&&) s) {}

template <class> using _error =
stdex::completion_signatures<>;
stdexec::completion_signatures<>;
template <class... Ts> using _value =
stdex::completion_signatures<stdex::set_value_t(Ts...)>;
stdexec::completion_signatures<stdexec::set_value_t(Ts...)>;

template <class Env>
friend auto tag_invoke(stdex::get_completion_signatures_t, const _retry_sender&, Env)
-> stdex::make_completion_signatures<
friend auto tag_invoke(stdexec::get_completion_signatures_t, const _retry_sender&, Env)
-> stdexec::make_completion_signatures<
S&, Env,
stdex::completion_signatures<stdex::set_error_t(std::exception_ptr)>,
stdexec::completion_signatures<stdexec::set_error_t(std::exception_ptr)>,
_value, _error>;

template<stdex::receiver R>
friend _op<S, R> tag_invoke(stdex::connect_t, _retry_sender&& self, R r) {
template<stdexec::receiver R>
friend _op<S, R> tag_invoke(stdexec::connect_t, _retry_sender&& self, R r) {
return {(S&&) self.s_, (R&&) r};
}
};

template<stdex::sender S>
stdex::sender auto retry(S s) {
template<stdexec::sender S>
stdexec::sender auto retry(S s) {
return _retry_sender{(S&&) s};
}
46 changes: 22 additions & 24 deletions examples/algorithms/then.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,70 +19,68 @@
// Pull in the reference implementation of P2300:
#include <stdexec/execution.hpp>

namespace stdex = std::execution;

///////////////////////////////////////////////////////////////////////////////
// then algorithm:
template<class R, class F>
class _then_receiver
: stdex::receiver_adaptor<_then_receiver<R, F>, R> {
friend stdex::receiver_adaptor<_then_receiver, R>;
: stdexec::receiver_adaptor<_then_receiver<R, F>, R> {
friend stdexec::receiver_adaptor<_then_receiver, R>;
F f_;

template <class... As>
using _completions =
stdex::completion_signatures<
stdex::set_value_t(std::invoke_result_t<F, As...>),
stdex::set_error_t(std::exception_ptr)>;
stdexec::completion_signatures<
stdexec::set_value_t(std::invoke_result_t<F, As...>),
stdexec::set_error_t(std::exception_ptr)>;

// Customize set_value by invoking the callable and passing the result to the inner receiver
template<class... As>
requires stdex::receiver_of<R, _completions<As...>>
requires stdexec::receiver_of<R, _completions<As...>>
void set_value(As&&... as) && noexcept try {
stdex::set_value(std::move(*this).base(), std::invoke((F&&) f_, (As&&) as...));
stdexec::set_value(std::move(*this).base(), std::invoke((F&&) f_, (As&&) as...));
} catch(...) {
stdex::set_error(std::move(*this).base(), std::current_exception());
stdexec::set_error(std::move(*this).base(), std::current_exception());
}

public:
_then_receiver(R r, F f)
: stdex::receiver_adaptor<_then_receiver, R>{std::move(r)}
: stdexec::receiver_adaptor<_then_receiver, R>{std::move(r)}
, f_(std::move(f)) {}
};

template<stdex::sender S, class F>
template<stdexec::sender S, class F>
struct _then_sender {
S s_;
F f_;

// Compute the completion signatures
template <class... Args>
using _set_value_t =
stdex::completion_signatures<
stdex::set_value_t(std::invoke_result_t<F, Args...>)>;
stdexec::completion_signatures<
stdexec::set_value_t(std::invoke_result_t<F, Args...>)>;

template <class Env>
using _completions_t =
stdex::make_completion_signatures<S, Env,
stdex::completion_signatures<stdex::set_error_t(std::exception_ptr)>,
stdexec::make_completion_signatures<S, Env,
stdexec::completion_signatures<stdexec::set_error_t(std::exception_ptr)>,
_set_value_t>;

template<class Env>
friend auto tag_invoke(stdex::get_completion_signatures_t, _then_sender&&, Env)
friend auto tag_invoke(stdexec::get_completion_signatures_t, _then_sender&&, Env)
-> _completions_t<Env>;

// Connect:
template<class R>
//requires stdex::receiver_of<R, _completions_t<stdex::env_of_t<R>>>
//requires stdex::receiver_of<R, stdex::completion_signatures_of_t<S, stdex::env_of_t<R>>>
friend auto tag_invoke(stdex::connect_t, _then_sender&& self, R r)
-> stdex::connect_result_t<S, _then_receiver<R, F>> {
return stdex::connect(
//requires stdexec::receiver_of<R, _completions_t<stdexec::env_of_t<R>>>
//requires stdexec::receiver_of<R, stdexec::completion_signatures_of_t<S, stdexec::env_of_t<R>>>
friend auto tag_invoke(stdexec::connect_t, _then_sender&& self, R r)
-> stdexec::connect_result_t<S, _then_receiver<R, F>> {
return stdexec::connect(
(S&&) self.s_, _then_receiver<R, F>{(R&&) r, (F&&) self.f_});
}
};

template<stdex::sender S, class F>
stdex::sender auto then(S s, F f) {
template<stdexec::sender S, class F>
stdexec::sender auto then(S s, F f) {
return _then_sender<S, F>{(S&&) s, (F&&) f};
}
6 changes: 3 additions & 3 deletions examples/hello_coro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#if !_STD_NO_COROUTINES_
#include <exec/task.hpp>

using namespace std::execution;
using namespace stdexec;

template <sender S1, sender S2>
exec::task<int> async_answer(S1 s1, S2 s2) {
Expand All @@ -36,13 +36,13 @@ exec::task<std::optional<int>> async_answer2(S1 s1, S2 s2) {
}

// tasks have an associated stop token
exec::task<std::optional<std::in_place_stop_token>> async_stop_token() {
exec::task<std::optional<stdexec::in_place_stop_token>> async_stop_token() {
co_return co_await stopped_as_optional(get_stop_token());
}

int main() try {
// Awaitables are implicitly senders:
auto [i] = std::this_thread::sync_wait(async_answer2(just(42), just())).value();
auto [i] = stdexec::sync_wait(async_answer2(just(42), just())).value();
std::cout << "The answer is " << i.value() << '\n';
} catch(std::exception & e) {
std::cout << e.what() << '\n';
Expand Down
4 changes: 2 additions & 2 deletions examples/hello_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

#include "exec/static_thread_pool.hpp"

using namespace std::execution;
using std::this_thread::sync_wait;
using namespace stdexec;
using stdexec::sync_wait;

int main() {
exec::static_thread_pool ctx{8};
Expand Down
4 changes: 2 additions & 2 deletions examples/nvexec/bulk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <cstdio>

namespace ex = std::execution;
namespace ex = stdexec;

int main() {
using nvexec::is_on_gpu;
Expand All @@ -30,6 +30,6 @@ int main() {
ex::schedule(sch) | ex::bulk(4, bulk_fn(2)))
| ex::then(then_fn(2));

std::this_thread::sync_wait(std::move(snd));
stdexec::sync_wait(std::move(snd));
}

Loading

0 comments on commit a4008ee

Please sign in to comment.