Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85749 - trunk/boost/asio
From: chris_at_[hidden]
Date: 2013-09-17 17:51:28


Author: chris_kohlhoff
Date: 2013-09-17 17:51:28 EDT (Tue, 17 Sep 2013)
New Revision: 85749
URL: http://svn.boost.org/trac/boost/changeset/85749

Log:
Enable the move optimisation (and otherwise eliminate a copy) for handlers
using the default invocation hook.

Text files modified:
   trunk/boost/asio/handler_invoke_hook.hpp | 29 ++++++++++++++++++++++-------
   1 files changed, 22 insertions(+), 7 deletions(-)

Modified: trunk/boost/asio/handler_invoke_hook.hpp
==============================================================================
--- trunk/boost/asio/handler_invoke_hook.hpp Tue Sep 17 17:48:54 2013 (r85748)
+++ trunk/boost/asio/handler_invoke_hook.hpp 2013-09-17 17:51:28 EDT (Tue, 17 Sep 2013) (r85749)
@@ -22,8 +22,10 @@
 namespace boost {
 namespace asio {
 
-/// Default invoke function for handlers.
-/**
+/** @defgroup asio_handler_invoke boost::asio::asio_handler_invoke
+ *
+ * @brief Default invoke function for handlers.
+ *
  * Completion handlers for asynchronous operations are invoked by the
  * io_service associated with the corresponding object (e.g. a socket or
  * deadline_timer). Certain guarantees are made on when the handler may be
@@ -42,10 +44,10 @@
  * Implement asio_handler_invoke for your own handlers to specify a custom
  * invocation strategy.
  *
- * This default implementation is simply:
- * @code
- * function();
- * @endcode
+ * This default implementation invokes the function object like so:
+ * @code function(); @endcode
+ * If necessary, the default implementation makes a copy of the function object
+ * so that the non-const operator() can be used.
  *
  * @par Example
  * @code
@@ -58,12 +60,25 @@
  * }
  * @endcode
  */
+/*@{*/
+
+/// Default handler invocation hook used for non-const function objects.
 template <typename Function>
-inline void asio_handler_invoke(Function function, ...)
+inline void asio_handler_invoke(Function& function, ...)
 {
   function();
 }
 
+/// Default handler invocation hook used for const function objects.
+template <typename Function>
+inline void asio_handler_invoke(const Function& function, ...)
+{
+ Function tmp(function);
+ tmp();
+}
+
+/*@}*/
+
 } // namespace asio
 } // namespace boost
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk