Advertisement
Guest User

Untitled

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