static_require_concept.hpp 2.9 KB

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