submit_member.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // traits/submit_member.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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_TRAITS_SUBMIT_MEMBER_HPP
  11. #define BOOST_ASIO_TRAITS_SUBMIT_MEMBER_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. #if defined(BOOST_ASIO_HAS_DECLTYPE) \
  18. && defined(BOOST_ASIO_HAS_NOEXCEPT) \
  19. && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  20. # define BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT 1
  21. #endif // defined(BOOST_ASIO_HAS_DECLTYPE)
  22. // && defined(BOOST_ASIO_HAS_NOEXCEPT)
  23. // && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  24. #include <boost/asio/detail/push_options.hpp>
  25. namespace boost {
  26. namespace asio {
  27. namespace traits {
  28. template <typename S, typename R, typename = void>
  29. struct submit_member_default;
  30. template <typename S, typename R, typename = void>
  31. struct submit_member;
  32. } // namespace traits
  33. namespace detail {
  34. struct no_submit_member
  35. {
  36. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
  37. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
  38. };
  39. #if defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
  40. template <typename S, typename R, typename = void>
  41. struct submit_member_trait : no_submit_member
  42. {
  43. };
  44. template <typename S, typename R>
  45. struct submit_member_trait<S, R,
  46. typename void_type<
  47. decltype(declval<S>().submit(declval<R>()))
  48. >::type>
  49. {
  50. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  51. using result_type = decltype(
  52. declval<S>().submit(declval<R>()));
  53. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = noexcept(
  54. declval<S>().submit(declval<R>())));
  55. };
  56. #else // defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
  57. template <typename S, typename R, typename = void>
  58. struct submit_member_trait :
  59. conditional<
  60. is_same<S, typename remove_reference<S>::type>::value
  61. && is_same<R, typename decay<R>::type>::value,
  62. typename conditional<
  63. is_same<S, typename add_const<S>::type>::value,
  64. no_submit_member,
  65. traits::submit_member<typename add_const<S>::type, R>
  66. >::type,
  67. traits::submit_member<
  68. typename remove_reference<S>::type,
  69. typename decay<R>::type>
  70. >::type
  71. {
  72. };
  73. #endif // defined(BOOST_ASIO_HAS_DEDUCED_SUBMIT_MEMBER_TRAIT)
  74. } // namespace detail
  75. namespace traits {
  76. template <typename S, typename R, typename>
  77. struct submit_member_default :
  78. detail::submit_member_trait<S, R>
  79. {
  80. };
  81. template <typename S, typename R, typename>
  82. struct submit_member :
  83. submit_member_default<S, R>
  84. {
  85. };
  86. } // namespace traits
  87. } // namespace asio
  88. } // namespace boost
  89. #include <boost/asio/detail/pop_options.hpp>
  90. #endif // BOOST_ASIO_TRAITS_SUBMIT_MEMBER_HPP