static_require.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // traits/static_require.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_STATIC_REQUIRE_HPP
  11. #define ASIO_TRAITS_STATIC_REQUIRE_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. #include "asio/traits/static_query.hpp"
  18. #if defined(ASIO_HAS_DECLTYPE) \
  19. && defined(ASIO_HAS_NOEXCEPT)
  20. # define ASIO_HAS_DEDUCED_STATIC_REQUIRE_TRAIT 1
  21. #endif // defined(ASIO_HAS_DECLTYPE)
  22. // && defined(ASIO_HAS_NOEXCEPT)
  23. #include "asio/detail/push_options.hpp"
  24. namespace asio {
  25. namespace traits {
  26. template <typename T, typename Property, typename = void>
  27. struct static_require_default;
  28. template <typename T, typename Property, typename = void>
  29. struct static_require;
  30. } // namespace traits
  31. namespace detail {
  32. struct no_static_require
  33. {
  34. ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
  35. };
  36. template <typename T, typename Property, typename = void>
  37. struct static_require_trait :
  38. conditional<
  39. is_same<T, typename decay<T>::type>::value
  40. && is_same<Property, typename decay<Property>::type>::value,
  41. no_static_require,
  42. traits::static_require<
  43. typename decay<T>::type,
  44. typename decay<Property>::type>
  45. >::type
  46. {
  47. };
  48. #if defined(ASIO_HAS_DEDUCED_STATIC_REQUIRE_TRAIT)
  49. #if defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  50. template <typename T, typename Property>
  51. struct static_require_trait<T, Property,
  52. typename enable_if<
  53. decay<Property>::type::value() == traits::static_query<T, Property>::value()
  54. >::type>
  55. {
  56. ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  57. };
  58. #else // defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  59. false_type static_require_test(...);
  60. template <typename T, typename Property>
  61. true_type static_require_test(T*, Property*,
  62. typename enable_if<
  63. Property::value() == traits::static_query<T, Property>::value()
  64. >::type* = 0);
  65. template <typename T, typename Property>
  66. struct has_static_require
  67. {
  68. ASIO_STATIC_CONSTEXPR(bool, value =
  69. decltype((static_require_test)(
  70. static_cast<T*>(0), static_cast<Property*>(0)))::value);
  71. };
  72. template <typename T, typename Property>
  73. struct static_require_trait<T, Property,
  74. typename enable_if<
  75. has_static_require<typename decay<T>::type,
  76. typename decay<Property>::type>::value
  77. >::type>
  78. {
  79. ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  80. };
  81. #endif // defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  82. #endif // defined(ASIO_HAS_DEDUCED_STATIC_REQUIRE_TRAIT)
  83. } // namespace detail
  84. namespace traits {
  85. template <typename T, typename Property, typename>
  86. struct static_require_default : detail::static_require_trait<T, Property>
  87. {
  88. };
  89. template <typename T, typename Property, typename>
  90. struct static_require : static_require_default<T, Property>
  91. {
  92. };
  93. } // namespace traits
  94. } // namespace asio
  95. #include "asio/detail/pop_options.hpp"
  96. #endif // ASIO_TRAITS_STATIC_REQUIRE_HPP