static_require_concept.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // traits/static_require_concept.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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_CONCEPT_HPP
  11. #define BOOST_ASIO_TRAITS_STATIC_REQUIRE_CONCEPT_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. #define BOOST_ASIO_HAS_DEDUCED_STATIC_REQUIRE_CONCEPT_TRAIT 1
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. namespace traits {
  23. template <typename T, typename Property, typename = void>
  24. struct static_require_concept_default;
  25. template <typename T, typename Property, typename = void>
  26. struct static_require_concept;
  27. } // namespace traits
  28. namespace detail {
  29. struct no_static_require_concept
  30. {
  31. static constexpr bool is_valid = false;
  32. };
  33. template <typename T, typename Property, typename = void>
  34. struct static_require_concept_trait :
  35. conditional_t<
  36. is_same<T, decay_t<T>>::value
  37. && is_same<Property, decay_t<Property>>::value,
  38. no_static_require_concept,
  39. traits::static_require_concept<
  40. decay_t<T>,
  41. decay_t<Property>>
  42. >
  43. {
  44. };
  45. #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  46. template <typename T, typename Property>
  47. struct static_require_concept_trait<T, Property,
  48. enable_if_t<
  49. decay_t<Property>::value() == traits::static_query<T, Property>::value()
  50. >>
  51. {
  52. static constexpr bool is_valid = true;
  53. };
  54. #else // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  55. false_type static_require_concept_test(...);
  56. template <typename T, typename Property>
  57. true_type static_require_concept_test(T*, Property*,
  58. enable_if_t<
  59. Property::value() == traits::static_query<T, Property>::value()
  60. >* = 0);
  61. template <typename T, typename Property>
  62. struct has_static_require_concept
  63. {
  64. static constexpr bool value =
  65. decltype((static_require_concept_test)(
  66. static_cast<T*>(0), static_cast<Property*>(0)))::value;
  67. };
  68. template <typename T, typename Property>
  69. struct static_require_concept_trait<T, Property,
  70. enable_if_t<
  71. has_static_require_concept<decay_t<T>,
  72. decay_t<Property>>::value
  73. >>
  74. {
  75. static constexpr bool is_valid = true;
  76. };
  77. #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  78. } // namespace detail
  79. namespace traits {
  80. template <typename T, typename Property, typename>
  81. struct static_require_concept_default :
  82. detail::static_require_concept_trait<T, Property>
  83. {
  84. };
  85. template <typename T, typename Property, typename>
  86. struct static_require_concept : static_require_concept_default<T, Property>
  87. {
  88. };
  89. } // namespace traits
  90. } // namespace asio
  91. } // namespace boost
  92. #include <boost/asio/detail/pop_options.hpp>
  93. #endif // BOOST_ASIO_TRAITS_STATIC_REQUIRE_CONCEPT_HPP