static_query.hpp 3.0 KB

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