static_require.hpp 3.3 KB

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