Hi all,

Although the pattern of "passing the buck" has been mentioned in several places in the context of Boost.Asio, I didn't find any self-contained example that demonstrates it in a reusable manner.

So, after going through all the information I could find, I tried to create such an example that demonstrates it using C++03.I would like to ask for feedback related to the attached sample code (its "Test Infrastructure" and "Test Code" sections) and double check that it does indeed depict what "passing the buck" means.


For future reference I'm listing here the all the sources of information I could find related to the pattern of "passing the buck". it also turned out that a helper utility is needed in order to wrap boost::bind created handlers and have the wrapper integrate with the Asio customization points.


- N3388 paper: Using Asio with C++11
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3388.pdf
Chapter 7 describes this strategy to develop efficient and generic composed operations by letting their caller decide via the provided completion handler how the intermediary handlers should interact with the Asio customization points.

- Thinking Asynchronously: Designing Applications with Boost.Asio
https://github.com/boostcon/2011_presentations/raw/master/mon/thinking_asynchronously.pdf
The "Managing Complexity" chapter references the "pass the buck" strategy with slides 113 and 114  showing invocation and allocation hooks that call the hooks of a nested handler.

- The implementation of higher level functions from Boost.Asio like async_read or async_write.
The problem with them being an example of the pattern is that they are using custom classes for the intermediary operation handlers instead of relying on boost::bind to build them on the fly.
 
- Asio Samples project
http://sourceforge.net/projects/asio-samples
For example its handler wrapper: context_alloc_handler and its usage in the echo server implementation.

Thank you,
Sorin Fetche