use_promise.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // experimental/impl/use_promise.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2021-2023 Klemens D. Morgenstern
  6. // (klemens dot morgenstern at gmx dot net)
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef ASIO_EXPERIMENTAL_IMPL_USE_PROMISE_HPP
  12. #define ASIO_EXPERIMENTAL_IMPL_USE_PROMISE_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include "asio/detail/config.hpp"
  17. #include <memory>
  18. #include "asio/async_result.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. namespace experimental {
  22. template <typename Allocator>
  23. struct use_promise_t;
  24. namespace detail {
  25. template<typename Signature, typename Executor, typename Allocator>
  26. struct promise_handler;
  27. } // namespace detail
  28. } // namespace experimental
  29. #if !defined(GENERATING_DOCUMENTATION)
  30. template <typename Allocator, typename R, typename... Args>
  31. struct async_result<experimental::use_promise_t<Allocator>, R(Args...)>
  32. {
  33. template <typename Initiation, typename... InitArgs>
  34. static auto initiate(Initiation initiation,
  35. experimental::use_promise_t<Allocator> up, InitArgs... args)
  36. -> experimental::promise<void(decay_t<Args>...),
  37. asio::associated_executor_t<Initiation>, Allocator>
  38. {
  39. using handler_type = experimental::detail::promise_handler<
  40. void(decay_t<Args>...),
  41. asio::associated_executor_t<Initiation>, Allocator>;
  42. handler_type ht{up.get_allocator(), get_associated_executor(initiation)};
  43. std::move(initiation)(ht, std::move(args)...);
  44. return ht.make_promise();
  45. }
  46. };
  47. #endif // !defined(GENERATING_DOCUMENTATION)
  48. } // namespace asio
  49. #include "asio/detail/pop_options.hpp"
  50. #endif // ASIO_EXPERIMENTAL_IMPL_USE_PROMISE_HPP