Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. // Return io_context* from io_context::executor_type
  2. inline
  3. net::io_context*
  4. get_io_context_impl(
  5. net::io_context::executor_type const& ex)
  6. {
  7. return &ex.context();
  8. }
  9.  
  10. // Return io_context* from net::executor
  11. template<class T
  12. , class = typename std::enable_if_t<
  13. std::is_same<T, net::executor>::value>::type>
  14. net::io_context*
  15. get_io_context_impl(
  16. T const& ex)
  17. {
  18. auto p = ex.target<
  19. net::io_context::executor_type>();
  20. if(! p)
  21. return nullptr;
  22. return &p->context();
  23. }
  24.  
  25. template<class T>
  26. net::io_context*
  27. get_io_context_impl(T const&)
  28. {
  29. return nullptr;
  30. }
  31.  
  32. template<class T>
  33. net::io_context*
  34. get_io_context_impl(T& t, std::true_type)
  35. {
  36. return get_io_context_impl(
  37. t.get_executor());
  38. }
  39.  
  40. template<class T>
  41. net::io_context*
  42. get_io_context_impl(T&, std::false_type)
  43. {
  44. return nullptr;
  45. }
  46.  
  47. template<class Executor>
  48. net::io_context*
  49. get_io_context(net::strand<Executor> const& strand)
  50. {
  51. return get_io_context_impl(
  52. strand.get_inner_executor());
  53. }
  54.  
  55. template<class T>
  56. net::io_context*
  57. get_io_context(T& t)
  58. {
  59. return get_io_context_impl(t,
  60. has_get_executor<T>{});
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement