prepend.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // experimental/prepend.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2022 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. #ifndef BOOST_ASIO_EXPERIMENTAL_PREPEND_HPP
  11. #define BOOST_ASIO_EXPERIMENTAL_PREPEND_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <tuple>
  17. #include <boost/asio/detail/type_traits.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace experimental {
  22. /// Completion token type used to specify that the completion handler
  23. /// arguments should be passed additional values before the results of the
  24. /// operation.
  25. template <typename CompletionToken, typename... Values>
  26. class prepend_t
  27. {
  28. public:
  29. /// Constructor.
  30. template <typename T, typename... V>
  31. BOOST_ASIO_CONSTEXPR explicit prepend_t(
  32. BOOST_ASIO_MOVE_ARG(T) completion_token,
  33. BOOST_ASIO_MOVE_ARG(V)... values)
  34. : token_(BOOST_ASIO_MOVE_CAST(T)(completion_token)),
  35. values_(BOOST_ASIO_MOVE_CAST(V)(values)...)
  36. {
  37. }
  38. //private:
  39. CompletionToken token_;
  40. std::tuple<Values...> values_;
  41. };
  42. /// Completion token type used to specify that the completion handler
  43. /// arguments should be passed additional values before the results of the
  44. /// operation.
  45. template <typename CompletionToken, typename... Values>
  46. BOOST_ASIO_NODISCARD inline BOOST_ASIO_CONSTEXPR prepend_t<
  47. typename decay<CompletionToken>::type, typename decay<Values>::type...>
  48. prepend(BOOST_ASIO_MOVE_ARG(CompletionToken) completion_token,
  49. BOOST_ASIO_MOVE_ARG(Values)... values)
  50. {
  51. return prepend_t<
  52. typename decay<CompletionToken>::type, typename decay<Values>::type...>(
  53. BOOST_ASIO_MOVE_CAST(CompletionToken)(completion_token),
  54. BOOST_ASIO_MOVE_CAST(Values)(values)...);
  55. }
  56. } // namespace experimental
  57. } // namespace asio
  58. } // namespace boost
  59. #include <boost/asio/detail/pop_options.hpp>
  60. #include <boost/asio/experimental/impl/prepend.hpp>
  61. #endif // BOOST_ASIO_EXPERIMENTAL_PREPEND_HPP