prepend.hpp 1.7 KB

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