query_static_constexpr_member.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // traits/query_static_constexpr_member.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_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_DECLTYPE) \
  18. && defined(ASIO_HAS_NOEXCEPT) \
  19. && defined(ASIO_HAS_CONSTEXPR) \
  20. && defined(ASIO_HAS_CONSTANT_EXPRESSION_SFINAE) \
  21. && defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  22. # define ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT 1
  23. #endif // defined(ASIO_HAS_DECLTYPE)
  24. // && defined(ASIO_HAS_NOEXCEPT)
  25. // && defined(ASIO_HAS_CONSTEXPR)
  26. // && defined(ASIO_HAS_CONSTANT_EXPRESSION_SFINAE)
  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 query_static_constexpr_member_default;
  33. template <typename T, typename Property, typename = void>
  34. struct query_static_constexpr_member;
  35. } // namespace traits
  36. namespace detail {
  37. struct no_query_static_constexpr_member
  38. {
  39. ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
  40. };
  41. template <typename T, typename Property, typename = void>
  42. struct query_static_constexpr_member_trait :
  43. conditional<
  44. is_same<T, typename decay<T>::type>::value
  45. && is_same<Property, typename decay<Property>::type>::value,
  46. no_query_static_constexpr_member,
  47. traits::query_static_constexpr_member<
  48. typename decay<T>::type,
  49. typename decay<Property>::type>
  50. >::type
  51. {
  52. };
  53. #if defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  54. template <typename T, typename Property>
  55. struct query_static_constexpr_member_trait<T, Property,
  56. typename enable_if<
  57. (static_cast<void>(T::query(Property{})), true)
  58. >::type>
  59. {
  60. ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  61. using result_type = decltype(T::query(Property{}));
  62. ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
  63. noexcept(T::query(Property{})));
  64. static ASIO_CONSTEXPR result_type value() noexcept(is_noexcept)
  65. {
  66. return T::query(Property{});
  67. }
  68. };
  69. #endif // defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  70. } // namespace detail
  71. namespace traits {
  72. template <typename T, typename Property, typename>
  73. struct query_static_constexpr_member_default :
  74. detail::query_static_constexpr_member_trait<T, Property>
  75. {
  76. };
  77. template <typename T, typename Property, typename>
  78. struct query_static_constexpr_member :
  79. query_static_constexpr_member_default<T, Property>
  80. {
  81. };
  82. } // namespace traits
  83. } // namespace asio
  84. #include "asio/detail/pop_options.hpp"
  85. #endif // ASIO_TRAITS_QUERY_STATIC_CONSTEXPR_MEMBER_HPP