default_completion_token.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // default_completion_token.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_HPP
  11. #define BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/type_traits.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. class deferred_t;
  21. namespace detail {
  22. template <typename T, typename = void>
  23. struct default_completion_token_impl
  24. {
  25. typedef deferred_t type;
  26. };
  27. template <typename T>
  28. struct default_completion_token_impl<T,
  29. void_t<typename T::default_completion_token_type>
  30. >
  31. {
  32. typedef typename T::default_completion_token_type type;
  33. };
  34. } // namespace detail
  35. #if defined(GENERATING_DOCUMENTATION)
  36. /// Traits type used to determine the default completion token type associated
  37. /// with a type (such as an executor).
  38. /**
  39. * A program may specialise this traits type if the @c T template parameter in
  40. * the specialisation is a user-defined type.
  41. *
  42. * Specialisations of this trait may provide a nested typedef @c type, which is
  43. * a default-constructible completion token type.
  44. *
  45. * If not otherwise specialised, the default completion token type is
  46. * boost::asio::deferred_t.
  47. */
  48. template <typename T>
  49. struct default_completion_token
  50. {
  51. /// If @c T has a nested type @c default_completion_token_type,
  52. /// <tt>T::default_completion_token_type</tt>. Otherwise the typedef @c type
  53. /// is boost::asio::deferred_t.
  54. typedef see_below type;
  55. };
  56. #else
  57. template <typename T>
  58. struct default_completion_token
  59. : detail::default_completion_token_impl<T>
  60. {
  61. };
  62. #endif
  63. template <typename T>
  64. using default_completion_token_t = typename default_completion_token<T>::type;
  65. #define BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \
  66. = typename ::boost::asio::default_completion_token<e>::type
  67. #define BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(e) \
  68. = typename ::boost::asio::default_completion_token<e>::type()
  69. } // namespace asio
  70. } // namespace boost
  71. #include <boost/asio/detail/pop_options.hpp>
  72. #include <boost/asio/deferred.hpp>
  73. #endif // BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_HPP