diff --git a/include/unifex/connect_awaitable.hpp b/include/unifex/connect_awaitable.hpp index 3cb21f91..e8f5586c 100644 --- a/include/unifex/connect_awaitable.hpp +++ b/include/unifex/connect_awaitable.hpp @@ -70,26 +70,26 @@ class _sender_task::type { bool await_ready() noexcept { return false; } void await_suspend(coro::coroutine_handle) noexcept( std::is_nothrow_invocable_v) { - ((Func&&)func_)(); + std::forward(func_)(); } [[noreturn]] void await_resume() noexcept { std::terminate(); } }; template auto yield_value(Func&& func) noexcept { - return awaiter{static_cast(func)}; + return awaiter{std::forward(func)}; } template auto await_transform(Value&& value) -> decltype(auto) { - return unifex::await_transform(*this, (Value&&)value); + return unifex::await_transform(*this, std::forward(value)); } #if UNIFEX_ENABLE_CONTINUATION_VISITATIONS template friend void tag_invoke(tag_t, const promise_type& p, Func&& func) { - visit_continuations(p.receiver_, (Func&&)func); + visit_continuations(p.receiver_, std::forward(func)); } #endif @@ -133,7 +133,7 @@ inline const struct _fn { struct _comma_hack { template friend T&& operator,(T&& t, _comma_hack) noexcept { - return (T&&)t; + return std::forward(t); } operator unit() const noexcept { return {}; } }; @@ -170,14 +170,14 @@ inline const struct _fn { unifex::set_value(std::move(receiver)); } else { unifex::set_value( - std::move(receiver), static_cast(result)); + std::move(receiver), std::forward(result)); } }; // The _comma_hack here makes this well-formed when the co_await // expression has type void. This could potentially run into trouble // if the type of the co_await expression itself overloads operator // comma, but that's pretty unlikely. - }((co_await (Awaitable&&) awaitable, _comma_hack{})); + }((co_await std::move(awaitable), _comma_hack{})); #if !UNIFEX_NO_EXCEPTIONS } catch (...) { ex = std::current_exception(); @@ -192,7 +192,8 @@ inline const struct _fn { template auto operator()(Awaitable&& awaitable, Receiver&& receiver) const -> _await::sender_task> { - return connect_impl((Awaitable&&)awaitable, (Receiver&&)receiver); + return connect_impl( + std::forward(awaitable), std::forward(receiver)); } } connect_awaitable{}; } // namespace _await_cpo @@ -217,13 +218,14 @@ struct _sndr { static constexpr bool sends_done = true; explicit type(Awaitable awaitable, instruction_ptr returnAddress) - : awaitable_((Awaitable&&)awaitable) + : awaitable_(std::move(awaitable)) , returnAddress_(returnAddress) {} template(typename Receiver) // (requires receiver_of) // friend auto tag_invoke(tag_t, type&& t, Receiver&& r) { - return unifex::connect_awaitable(((type&&)t).awaitable_, (Receiver&&)r); + return unifex::connect_awaitable( + std::move(t).awaitable_, std::forward(r)); } // TODO: how do we make this property statically discoverable? @@ -260,13 +262,14 @@ struct _sndr { explicit type(Awaitable awaitable, instruction_ptr returnAddress) noexcept( std::is_nothrow_move_constructible_v) - : awaitable_((Awaitable&&)awaitable) + : awaitable_(std::move(awaitable)) , returnAddress_(returnAddress) {} template(typename Receiver) // (requires receiver_of) // friend auto tag_invoke(tag_t, type&& t, Receiver&& r) { - return unifex::connect_awaitable(((type&&)t).awaitable_, (Receiver&&)r); + return unifex::connect_awaitable( + std::move(t).awaitable_, std::forward(r)); } // TODO: how do we make this property statically discoverable? @@ -295,7 +298,8 @@ struct _fn { _sender> operator()(Awaitable&& awaitable) const { return _sender>{ - (Awaitable&&)awaitable, instruction_ptr::read_return_address()}; + std::forward(awaitable), + instruction_ptr::read_return_address()}; } }; } // namespace _as_sender