static_query.hpp 2.6 KB

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