1//
2// detached.hpp
3// ~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6//
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)
9//
10
11#ifndef BOOST_ASIO_DETACHED_HPP
12#define BOOST_ASIO_DETACHED_HPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18#include <boost/asio/detail/config.hpp>
19#include <memory>
20#include <boost/asio/detail/type_traits.hpp>
21
22#include <boost/asio/detail/push_options.hpp>
23
24namespace boost {
25namespace asio {
26
27/// A @ref completion_token type used to specify that an asynchronous operation
28/// is detached.
29/**
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:
35 *
36 * @code my_socket.async_send(my_buffer, boost::asio::detached);
37 * @endcode
38 */
39class detached_t
40{
41public:
42 /// Constructor.
43 constexpr detached_t()
44 {
45 }
46
47 /// Adapts an executor to add the @c detached_t completion token as the
48 /// default.
49 template <typename InnerExecutor>
50 struct executor_with_default : InnerExecutor
51 {
52 /// Specify @c detached_t as the default completion token type.
53 typedef detached_t default_completion_token_type;
54
55 /// Construct the adapted executor from the inner executor type.
56 executor_with_default(const InnerExecutor& ex) noexcept
57 : InnerExecutor(ex)
58 {
59 }
60
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,
65 constraint_t<
66 is_convertible<OtherExecutor, InnerExecutor>::value
67 > = 0) noexcept
68 : InnerExecutor(ex)
69 {
70 }
71 };
72
73 /// Type alias to adapt an I/O object to use @c detached_t as its
74 /// default completion token type.
75 template <typename T>
76 using as_default_on_t = typename T::template rebind_executor<
77 executor_with_default<typename T::executor_type>>::other;
78
79 /// Function helper to adapt an I/O object to use @c detached_t as its
80 /// default completion token type.
81 template <typename T>
82 static typename decay_t<T>::template rebind_executor<
83 executor_with_default<typename decay_t<T>::executor_type>
84 >::other
85 as_default_on(T&& object)
86 {
87 return typename decay_t<T>::template rebind_executor<
88 executor_with_default<typename decay_t<T>::executor_type>
89 >::other(static_cast<T&&>(object));
90 }
91};
92
93/// A @ref completion_token object used to specify that an asynchronous
94/// operation is detached.
95/**
96 * See the documentation for boost::asio::detached_t for a usage example.
97 */
98constexpr detached_t detached;
99
100} // namespace asio
101} // namespace boost
102
103#include <boost/asio/detail/pop_options.hpp>
104
105#include <boost/asio/impl/detached.hpp>
106
107#endif // BOOST_ASIO_DETACHED_HPP
108

source code of boost/libs/asio/include/boost/asio/detached.hpp