1//
2// consign.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_CONSIGN_HPP
12#define BOOST_ASIO_CONSIGN_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 <tuple>
20#include <boost/asio/detail/type_traits.hpp>
21
22#include <boost/asio/detail/push_options.hpp>
23
24namespace boost {
25namespace asio {
26
27/// Completion token type used to specify that the completion handler should
28/// carry additional values along with it.
29/**
30 * This completion token adapter is typically used to keep at least one copy of
31 * an object, such as a smart pointer, alive until the completion handler is
32 * called.
33 */
34template <typename CompletionToken, typename... Values>
35class consign_t
36{
37public:
38 /// Constructor.
39 template <typename T, typename... V>
40 constexpr explicit consign_t(T&& completion_token, V&&... values)
41 : token_(static_cast<T&&>(completion_token)),
42 values_(static_cast<V&&>(values)...)
43 {
44 }
45
46#if defined(GENERATING_DOCUMENTATION)
47private:
48#endif // defined(GENERATING_DOCUMENTATION)
49 CompletionToken token_;
50 std::tuple<Values...> values_;
51};
52
53/// Completion token adapter used to specify that the completion handler should
54/// carry additional values along with it.
55/**
56 * This completion token adapter is typically used to keep at least one copy of
57 * an object, such as a smart pointer, alive until the completion handler is
58 * called.
59 */
60template <typename CompletionToken, typename... Values>
61BOOST_ASIO_NODISCARD inline constexpr
62consign_t<decay_t<CompletionToken>, decay_t<Values>...>
63consign(CompletionToken&& completion_token, Values&&... values)
64{
65 return consign_t<decay_t<CompletionToken>, decay_t<Values>...>(
66 static_cast<CompletionToken&&>(completion_token),
67 static_cast<Values&&>(values)...);
68}
69
70} // namespace asio
71} // namespace boost
72
73#include <boost/asio/detail/pop_options.hpp>
74
75#include <boost/asio/impl/consign.hpp>
76
77#endif // BOOST_ASIO_CONSIGN_HPP
78

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