query_member.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // traits/query_member.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2022 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_TRAITS_QUERY_MEMBER_HPP
  11. #define ASIO_TRAITS_QUERY_MEMBER_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/type_traits.hpp"
  17. #if defined(ASIO_HAS_DECLTYPE) \
  18. && defined(ASIO_HAS_NOEXCEPT) \
  19. && defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  20. # define ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT 1
  21. #endif // defined(ASIO_HAS_DECLTYPE)
  22. // && defined(ASIO_HAS_NOEXCEPT)
  23. // && defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  24. #include "asio/detail/push_options.hpp"
  25. namespace asio {
  26. namespace traits {
  27. template <typename T, typename Property, typename = void>
  28. struct query_member_default;
  29. template <typename T, typename Property, typename = void>
  30. struct query_member;
  31. } // namespace traits
  32. namespace detail {
  33. struct no_query_member
  34. {
  35. ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
  36. ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
  37. };
  38. #if defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  39. template <typename T, typename Property, typename = void>
  40. struct query_member_trait : no_query_member
  41. {
  42. };
  43. template <typename T, typename Property>
  44. struct query_member_trait<T, Property,
  45. typename void_type<
  46. decltype(declval<T>().query(declval<Property>()))
  47. >::type>
  48. {
  49. ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  50. using result_type = decltype(
  51. declval<T>().query(declval<Property>()));
  52. ASIO_STATIC_CONSTEXPR(bool, is_noexcept = noexcept(
  53. declval<T>().query(declval<Property>())));
  54. };
  55. #else // defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  56. template <typename T, typename Property, typename = void>
  57. struct query_member_trait :
  58. conditional<
  59. is_same<T, typename decay<T>::type>::value
  60. && is_same<Property, typename decay<Property>::type>::value,
  61. no_query_member,
  62. traits::query_member<
  63. typename decay<T>::type,
  64. typename decay<Property>::type>
  65. >::type
  66. {
  67. };
  68. #endif // defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  69. } // namespace detail
  70. namespace traits {
  71. template <typename T, typename Property, typename>
  72. struct query_member_default :
  73. detail::query_member_trait<T, Property>
  74. {
  75. };
  76. template <typename T, typename Property, typename>
  77. struct query_member :
  78. query_member_default<T, Property>
  79. {
  80. };
  81. } // namespace traits
  82. } // namespace asio
  83. #include "asio/detail/pop_options.hpp"
  84. #endif // ASIO_TRAITS_QUERY_MEMBER_HPP