prepend.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // prepend.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. #ifndef BOOST_ASIO_PREPEND_HPP
  11. #define BOOST_ASIO_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. /// Completion token type used to specify that the completion handler
  22. /// arguments should be passed additional values before the results of the
  23. /// operation.
  24. template <typename CompletionToken, typename... Values>
  25. class prepend_t
  26. {
  27. public:
  28. /// Constructor.
  29. template <typename T, typename... V>
  30. constexpr explicit prepend_t(T&& completion_token, V&&... values)
  31. : token_(static_cast<T&&>(completion_token)),
  32. values_(static_cast<V&&>(values)...)
  33. {
  34. }
  35. //private:
  36. CompletionToken token_;
  37. std::tuple<Values...> values_;
  38. };
  39. /// Completion token type used to specify that the completion handler
  40. /// arguments should be passed additional values before the results of the
  41. /// operation.
  42. template <typename CompletionToken, typename... Values>
  43. BOOST_ASIO_NODISCARD inline constexpr
  44. prepend_t<decay_t<CompletionToken>, decay_t<Values>...>
  45. prepend(CompletionToken&& completion_token,
  46. Values&&... values)
  47. {
  48. return prepend_t<decay_t<CompletionToken>, decay_t<Values>...>(
  49. static_cast<CompletionToken&&>(completion_token),
  50. static_cast<Values&&>(values)...);
  51. }
  52. } // namespace asio
  53. } // namespace boost
  54. #include <boost/asio/detail/pop_options.hpp>
  55. #include <boost/asio/impl/prepend.hpp>
  56. #endif // BOOST_ASIO_PREPEND_HPP