prepend.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 ASIO_EXPERIMENTAL_PREPEND_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #include <tuple>
  17. #include "asio/detail/type_traits.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace experimental {
  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. ASIO_CONSTEXPR explicit prepend_t(
  31. ASIO_MOVE_ARG(T) completion_token,
  32. ASIO_MOVE_ARG(V)... values)
  33. : token_(ASIO_MOVE_CAST(T)(completion_token)),
  34. values_(ASIO_MOVE_CAST(V)(values)...)
  35. {
  36. }
  37. //private:
  38. CompletionToken token_;
  39. std::tuple<Values...> values_;
  40. };
  41. /// Completion token type used to specify that the completion handler
  42. /// arguments should be passed additional values before the results of the
  43. /// operation.
  44. template <typename CompletionToken, typename... Values>
  45. ASIO_NODISCARD inline ASIO_CONSTEXPR prepend_t<
  46. typename decay<CompletionToken>::type, typename decay<Values>::type...>
  47. prepend(ASIO_MOVE_ARG(CompletionToken) completion_token,
  48. ASIO_MOVE_ARG(Values)... values)
  49. {
  50. return prepend_t<
  51. typename decay<CompletionToken>::type, typename decay<Values>::type...>(
  52. ASIO_MOVE_CAST(CompletionToken)(completion_token),
  53. ASIO_MOVE_CAST(Values)(values)...);
  54. }
  55. } // namespace experimental
  56. } // namespace asio
  57. #include "asio/detail/pop_options.hpp"
  58. #include "asio/experimental/impl/prepend.hpp"
  59. #endif // ASIO_EXPERIMENTAL_PREPEND_HPP