Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection::async_exec() requires a copyable CompletionToken #131

Closed
cbodley opened this issue Aug 2, 2023 · 0 comments · Fixed by #132
Closed

connection::async_exec() requires a copyable CompletionToken #131

cbodley opened this issue Aug 2, 2023 · 0 comments · Fixed by #132

Comments

@cbodley
Copy link
Contributor

cbodley commented Aug 2, 2023

with gcc 13.1.1, boost 1.82, and redis develop branch at commit 7d16259:

#include <boost/asio.hpp>
#include <boost/redis.hpp>

struct move_only_handler {
  move_only_handler(const move_only_handler&) = delete;
  move_only_handler(move_only_handler&&) = default;

  void operator()(boost::system::error_code, std::size_t);
};

int main(int argc, char** argv)
{
  boost::asio::io_context ioctx;
  boost::redis::connection conn{ioctx};

  boost::redis::request request;
  boost::redis::response<std::string> response;
  conn.async_exec(request, response, move_only_handler{});
}

compilation fails with:

~/test/redis_exec $ g++ main.cc -Iboost/include -I redis/include
In file included from redis/include/boost/redis.hpp:12,
                 from main.cc:2:
redis/include/boost/redis/connection.hpp: In instantiation of ‘auto boost::redis::basic_connection<Executor>::async_exec(const boost::redis::request&, Response&, CompletionToken) [with Response = std::tuple<boost::system::result<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::redis::adapter::error> >; CompletionToken = move_only_handler; Executor = boost::asio::any_io_executor]’:
redis/include/boost/redis/connection.hpp:354:30:   required from ‘auto boost::redis::connection::async_exec(const boost::redis::request&, Response&, CompletionToken) [with Response = std::tuple<boost::system::result<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::redis::adapter::error> >; CompletionToken = move_only_handler]’
main.cc:18:18:   required from here
redis/include/boost/redis/connection.hpp:232:30: error: use of deleted function ‘move_only_handler::move_only_handler(const move_only_handler&)’
  232 |       return impl_.async_exec(req, resp, token);
      |              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
main.cc:5:3: note: declared here
    5 |   move_only_handler(const move_only_handler&) = delete;
      |   ^~~~~~~~~~~~~~~~~
In file included from redis/include/boost/redis/connection.hpp:10:
redis/include/boost/redis/detail/connection_base.hpp:556:72: note:   initializing argument 3 of ‘auto boost::redis::detail::connection_base<Executor>::async_exec(const boost::redis::request&, Response&, CompletionToken) [with Response = std::tuple<boost::system::result<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::redis::adapter::error> >; CompletionToken = move_only_handler; Executor = boost::asio::any_io_executor]’
  556 |    auto async_exec(request const& req, Response& resp, CompletionToken token)
      |                                                        ~~~~~~~~~~~~~~~~^~~~~
cbodley added a commit to cbodley/redis that referenced this issue Aug 2, 2023
async operations should support move-only completion handlers. forward
the CompletionToken argument to avoid an unnecessary copy

Fixes: boostorg#131

Signed-off-by: Casey Bodley <cbodley@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant