// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2018 Red Hat * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_ASYNC_FORWARD_HANDLER_H #define CEPH_ASYNC_FORWARD_HANDLER_H #include namespace ceph::async { /** * A forwarding completion handler for use with boost::asio. * * A completion handler wrapper that invokes the handler's operator() as an * rvalue, regardless of whether the wrapper is invoked as an lvalue or rvalue. * This operation is potentially destructive to the wrapped handler, so is only * suitable for single-use handlers. * * This is useful when combined with bind_handler() and move-only arguments, * because executors will always call the lvalue overload of operator(). * * The original Handler's associated allocator and executor are maintained. * * @see forward_handler */ template struct ForwardingHandler { Handler handler; ForwardingHandler(Handler&& handler) : handler(std::move(handler)) {} template void operator()(Args&& ...args) { std::move(handler)(std::forward(args)...); } }; } // namespace ceph::async namespace boost::asio { // forward the handler's associated executor, allocator, cancellation slot, etc template