static_query.hpp 2.5 KB

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