static_query.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // traits/static_query.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_STATIC_QUERY_HPP
  11. #define ASIO_TRAITS_STATIC_QUERY_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_CONSTEXPR) \
  20. && defined(ASIO_HAS_VARIABLE_TEMPLATES) \
  21. && defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  22. # define ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT 1
  23. #endif // defined(ASIO_HAS_DECLTYPE)
  24. // && defined(ASIO_HAS_NOEXCEPT)
  25. // && defined(ASIO_HAS_CONSTEXPR)
  26. // && defined(ASIO_HAS_VARIABLE_TEMPLATES)
  27. // && defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  28. #include "asio/detail/push_options.hpp"
  29. namespace asio {
  30. namespace traits {
  31. template <typename T, typename Property, typename = void>
  32. struct static_query_default;
  33. template <typename T, typename Property, typename = void>
  34. struct static_query;
  35. } // namespace traits
  36. namespace detail {
  37. struct no_static_query
  38. {
  39. ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
  40. ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
  41. };
  42. template <typename T, typename Property, typename = void>
  43. struct static_query_trait :
  44. conditional<
  45. is_same<T, typename decay<T>::type>::value
  46. && is_same<Property, typename decay<Property>::type>::value,
  47. no_static_query,
  48. traits::static_query<
  49. typename decay<T>::type,
  50. typename decay<Property>::type>
  51. >::type
  52. {
  53. };
  54. #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  55. template <typename T, typename Property>
  56. struct static_query_trait<T, Property,
  57. typename void_type<
  58. decltype(decay<Property>::type::template static_query_v<T>)
  59. >::type>
  60. {
  61. ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  62. using result_type = decltype(
  63. decay<Property>::type::template static_query_v<T>);
  64. ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
  65. noexcept(decay<Property>::type::template static_query_v<T>));
  66. static ASIO_CONSTEXPR result_type value() noexcept(is_noexcept)
  67. {
  68. return decay<Property>::type::template static_query_v<T>;
  69. }
  70. };
  71. #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  72. } // namespace detail
  73. namespace traits {
  74. template <typename T, typename Property, typename>
  75. struct static_query_default : detail::static_query_trait<T, Property>
  76. {
  77. };
  78. template <typename T, typename Property, typename>
  79. struct static_query : static_query_default<T, Property>
  80. {
  81. };
  82. } // namespace traits
  83. } // namespace asio
  84. #include "asio/detail/pop_options.hpp"
  85. #endif // ASIO_TRAITS_STATIC_QUERY_HPP