Chris@16: // Chris@16: // async_result.hpp Chris@16: // ~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_ASYNC_RESULT_HPP Chris@16: #define BOOST_ASIO_ASYNC_RESULT_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: Chris@16: /// An interface for customising the behaviour of an initiating function. Chris@16: /** Chris@16: * This template may be specialised for user-defined handler types. Chris@16: */ Chris@16: template Chris@16: class async_result Chris@16: { Chris@16: public: Chris@16: /// The return type of the initiating function. Chris@16: typedef void type; Chris@16: Chris@16: /// Construct an async result from a given handler. Chris@16: /** Chris@16: * When using a specalised async_result, the constructor has an opportunity Chris@16: * to initialise some state associated with the handler, which is then Chris@16: * returned from the initiating function. Chris@16: */ Chris@16: explicit async_result(Handler&) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Obtain the value to be returned from the initiating function. Chris@16: type get() Chris@16: { Chris@16: } Chris@16: }; Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: // Helper template to deduce the true type of a handler, capture a local copy Chris@16: // of the handler, and then create an async_result for the handler. Chris@16: template Chris@16: struct async_result_init Chris@16: { Chris@16: explicit async_result_init(BOOST_ASIO_MOVE_ARG(Handler) orig_handler) Chris@16: : handler(BOOST_ASIO_MOVE_CAST(Handler)(orig_handler)), Chris@16: result(handler) Chris@16: { Chris@16: } Chris@16: Chris@16: typename handler_type::type handler; Chris@16: async_result::type> result; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct async_result_type_helper Chris@16: { Chris@16: typedef typename async_result< Chris@16: typename handler_type::type Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: # define BOOST_ASIO_INITFN_RESULT_TYPE(h, sig) \ Chris@16: void_or_deduced Chris@16: #elif defined(_MSC_VER) && (_MSC_VER < 1500) Chris@16: # define BOOST_ASIO_INITFN_RESULT_TYPE(h, sig) \ Chris@16: typename ::boost::asio::detail::async_result_type_helper::type Chris@16: #else Chris@16: # define BOOST_ASIO_INITFN_RESULT_TYPE(h, sig) \ Chris@16: typename ::boost::asio::async_result< \ Chris@16: typename ::boost::asio::handler_type::type>::type Chris@16: #endif Chris@16: Chris@16: #endif // BOOST_ASIO_ASYNC_RESULT_HPP