use_promise.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 BOOST_ASIO_EXPERIMENTAL_IMPL_USE_PROMISE_HPP
  12. #define BOOST_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 <boost/asio/detail/config.hpp>
  17. #include <memory>
  18. #include <boost/asio/async_result.hpp>
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. namespace experimental {
  23. template <typename Allocator>
  24. struct use_promise_t;
  25. namespace detail {
  26. template<typename Signature, typename Executor, typename Allocator>
  27. struct promise_handler;
  28. } // namespace detail
  29. } // namespace experimental
  30. #if !defined(GENERATING_DOCUMENTATION)
  31. template <typename Allocator, typename R, typename... Args>
  32. struct async_result<experimental::use_promise_t<Allocator>, R(Args...)>
  33. {
  34. template <typename Initiation, typename... InitArgs>
  35. static auto initiate(Initiation initiation,
  36. experimental::use_promise_t<Allocator> up, InitArgs... args)
  37. -> experimental::promise<void(decay_t<Args>...),
  38. boost::asio::associated_executor_t<Initiation>, Allocator>
  39. {
  40. using handler_type = experimental::detail::promise_handler<
  41. void(decay_t<Args>...),
  42. boost::asio::associated_executor_t<Initiation>, Allocator>;
  43. handler_type ht{up.get_allocator(), get_associated_executor(initiation)};
  44. std::move(initiation)(ht, std::move(args)...);
  45. return ht.make_promise();
  46. }
  47. };
  48. #endif // !defined(GENERATING_DOCUMENTATION)
  49. } // namespace asio
  50. } // namespace boost
  51. #include <boost/asio/detail/pop_options.hpp>
  52. #endif // BOOST_ASIO_EXPERIMENTAL_IMPL_USE_PROMISE_HPP