Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

packaged_task.hpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // packaged_task.hpp
  3. // ~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_PACKAGED_TASK_HPP
  11. #define ASIO_PACKAGED_TASK_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 "asio/detail/future.hpp"
  17. #if defined(ASIO_HAS_STD_FUTURE_CLASS) \
  18. || defined(GENERATING_DOCUMENTATION)
  19. #include "asio/async_result.hpp"
  20. #include "asio/detail/type_traits.hpp"
  21. #include "asio/detail/variadic_templates.hpp"
  22. #include "asio/detail/push_options.hpp"
  23. namespace asio {
  24. #if defined(ASIO_HAS_VARIADIC_TEMPLATES) \
  25. || defined(GENERATING_DOCUMENTATION)
  26. /// Partial specialisation of @c async_result for @c std::packaged_task.
  27. template <typename Result, typename... Args, typename Signature>
  28. class async_result<std::packaged_task<Result(Args...)>, Signature>
  29. {
  30. public:
  31. /// The packaged task is the concrete completion handler type.
  32. typedef std::packaged_task<Result(Args...)> completion_handler_type;
  33. /// The return type of the initiating function is the future obtained from
  34. /// the packaged task.
  35. typedef std::future<Result> return_type;
  36. /// The constructor extracts the future from the packaged task.
  37. explicit async_result(completion_handler_type& h)
  38. : future_(h.get_future())
  39. {
  40. }
  41. /// Returns the packaged task's future.
  42. return_type get()
  43. {
  44. return std::move(future_);
  45. }
  46. private:
  47. return_type future_;
  48. };
  49. #else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
  50. // || defined(GENERATING_DOCUMENTATION)
  51. template <typename Result, typename Signature>
  52. struct async_result<std::packaged_task<Result()>, Signature>
  53. {
  54. typedef std::packaged_task<Result()> completion_handler_type;
  55. typedef std::future<Result> return_type;
  56. explicit async_result(completion_handler_type& h)
  57. : future_(h.get_future())
  58. {
  59. }
  60. return_type get()
  61. {
  62. return std::move(future_);
  63. }
  64. private:
  65. return_type future_;
  66. };
  67. #define ASIO_PRIVATE_ASYNC_RESULT_DEF(n) \
  68. template <typename Result, \
  69. ASIO_VARIADIC_TPARAMS(n), typename Signature> \
  70. class async_result< \
  71. std::packaged_task<Result(ASIO_VARIADIC_TARGS(n))>, Signature> \
  72. { \
  73. public: \
  74. typedef std::packaged_task< \
  75. Result(ASIO_VARIADIC_TARGS(n))> \
  76. completion_handler_type; \
  77. \
  78. typedef std::future<Result> return_type; \
  79. \
  80. explicit async_result(completion_handler_type& h) \
  81. : future_(h.get_future()) \
  82. { \
  83. } \
  84. \
  85. return_type get() \
  86. { \
  87. return std::move(future_); \
  88. } \
  89. \
  90. private: \
  91. return_type future_; \
  92. }; \
  93. /**/
  94. ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_ASYNC_RESULT_DEF)
  95. #undef ASIO_PRIVATE_ASYNC_RESULT_DEF
  96. #endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
  97. // || defined(GENERATING_DOCUMENTATION)
  98. } // namespace asio
  99. #include "asio/detail/pop_options.hpp"
  100. #endif // defined(ASIO_HAS_STD_FUTURE_CLASS)
  101. // || defined(GENERATING_DOCUMENTATION)
  102. #endif // ASIO_PACKAGED_TASK_HPP