boostorg / asio

Boost.org asio module
http://boost.org/libs/asio
1.25k stars 418 forks source link

The modifications remove unnecessary uses of std::move() for improve… #421

Open ArielSilver opened 1 year ago

ArielSilver commented 1 year ago

This pull request addresses two modifications in the promise_impl class within the experimental/impl/promise.hpp file:

that there is indeed an unnecessary use of std::move() in the apply_impl function. Specifically, the line f(std::get(std::move(result_type))...); could be modified to remove the unnecessary std::move().

Here's the corrected version of the apply_impl function: template<typename Func, std::size_t... Idx> void apply_impl(Func f, boost::asio::detail::index_sequence) { auto& result_type = reinterpret_cast<promise_impl::result_type>(&result); f(std::get(result_type)...); // Remove std::move() } and In the operator() function of the promisehandler class, the modification involves removing the unnecessary use of std::move() when storing the result values in the promise object. The line new (&impl->result) result_type(ts...); initializes the result object by directly forwarding the ts arguments without using std::move().

This modification ensures that the result values are efficiently stored in the promise object without unnecessary moves. Certainly! Here's an explanation of the modifications made to the code:

**void operator()(std::remove_referencet... ts) { assert(impl);

using result_type = typename promise_impl< void(Ts...), allocator_type, executor_type>::result_type ;

new (&impl_->result) result_type(ts...); // Remove std::move()

impl_->done = true;

if (impl->completion) impl->complete_with_result(); }**