query_static_constexpr_member.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // traits/query_static_constexpr_member.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_QUERY_STATIC_CONSTEXPR_MEMBER_HPP
  11. #define ASIO_TRAITS_QUERY_STATIC_CONSTEXPR_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_CONSTANT_EXPRESSION_SFINAE) \
  18. && defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  19. # define ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT 1
  20. #endif // defined(ASIO_HAS_CONSTANT_EXPRESSION_SFINAE)
  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 query_static_constexpr_member_default;
  27. template <typename T, typename Property, typename = void>
  28. struct query_static_constexpr_member;
  29. } // namespace traits
  30. namespace detail {
  31. struct no_query_static_constexpr_member
  32. {
  33. static constexpr bool is_valid = false;
  34. };
  35. template <typename T, typename Property, typename = void>
  36. struct query_static_constexpr_member_trait :
  37. conditional_t<
  38. is_same<T, decay_t<T>>::value
  39. && is_same<Property, decay_t<Property>>::value,
  40. no_query_static_constexpr_member,
  41. traits::query_static_constexpr_member<
  42. decay_t<T>,
  43. decay_t<Property>>
  44. >
  45. {
  46. };
  47. #if defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  48. template <typename T, typename Property>
  49. struct query_static_constexpr_member_trait<T, Property,
  50. enable_if_t<
  51. (static_cast<void>(T::query(Property{})), true)
  52. >>
  53. {
  54. static constexpr bool is_valid = true;
  55. using result_type = decltype(T::query(Property{}));
  56. static constexpr bool is_noexcept = noexcept(T::query(Property{}));
  57. static constexpr result_type value() noexcept(is_noexcept)
  58. {
  59. return T::query(Property{});
  60. }
  61. };
  62. #endif // defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  63. } // namespace detail
  64. namespace traits {
  65. template <typename T, typename Property, typename>
  66. struct query_static_constexpr_member_default :
  67. detail::query_static_constexpr_member_trait<T, Property>
  68. {
  69. };
  70. template <typename T, typename Property, typename>
  71. struct query_static_constexpr_member :
  72. query_static_constexpr_member_default<T, Property>
  73. {
  74. };
  75. } // namespace traits
  76. } // namespace asio
  77. #include "asio/detail/pop_options.hpp"
  78. #endif // ASIO_TRAITS_QUERY_STATIC_CONSTEXPR_MEMBER_HPP