5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETACHED_HPP
12 #define BOOST_ASIO_DETACHED_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #include <boost/asio/detail/type_traits.hpp>
22 #include <boost/asio/detail/push_options.hpp>
27 /// Class used to specify that an asynchronous operation is detached.
30 * The detached_t class is used to indicate that an asynchronous operation is
31 * detached. That is, there is no completion handler waiting for the
32 * operation's result. A detached_t object may be passed as a handler to an
33 * asynchronous operation, typically using the special value
34 * @c boost::asio::detached. For example:
36 * @code my_socket.async_send(my_buffer, boost::asio::detached);
43 BOOST_ASIO_CONSTEXPR detached_t()
47 /// Adapts an executor to add the @c detached_t completion token as the
49 template <typename InnerExecutor>
50 struct executor_with_default : InnerExecutor
52 /// Specify @c detached_t as the default completion token type.
53 typedef detached_t default_completion_token_type;
55 /// Construct the adapted executor from the inner executor type.
56 executor_with_default(const InnerExecutor& ex) BOOST_ASIO_NOEXCEPT
61 /// Convert the specified executor to the inner executor type, then use
62 /// that to construct the adapted executor.
63 template <typename OtherExecutor>
64 executor_with_default(const OtherExecutor& ex,
66 is_convertible<OtherExecutor, InnerExecutor>::value
67 >::type* = 0) BOOST_ASIO_NOEXCEPT
73 /// Type alias to adapt an I/O object to use @c detached_t as its
74 /// default completion token type.
75 #if defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES) \
76 || defined(GENERATING_DOCUMENTATION)
78 using as_default_on_t = typename T::template rebind_executor<
79 executor_with_default<typename T::executor_type> >::other;
80 #endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
81 // || defined(GENERATING_DOCUMENTATION)
83 /// Function helper to adapt an I/O object to use @c detached_t as its
84 /// default completion token type.
86 static typename decay<T>::type::template rebind_executor<
87 executor_with_default<typename decay<T>::type::executor_type>
89 as_default_on(BOOST_ASIO_MOVE_ARG(T) object)
91 return typename decay<T>::type::template rebind_executor<
92 executor_with_default<typename decay<T>::type::executor_type>
93 >::other(BOOST_ASIO_MOVE_CAST(T)(object));
97 /// A special value, similar to std::nothrow.
99 * See the documentation for boost::asio::detached_t for a usage example.
101 #if defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
102 constexpr detached_t detached;
103 #elif defined(BOOST_ASIO_MSVC)
104 __declspec(selectany) detached_t detached;
110 #include <boost/asio/detail/pop_options.hpp>
112 #include <boost/asio/impl/detached.hpp>
114 #endif // BOOST_ASIO_DETACHED_HPP