execution_concepts.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MYSQL_DETAIL_EXECUTION_CONCEPTS_HPP
  8. #define BOOST_MYSQL_DETAIL_EXECUTION_CONCEPTS_HPP
  9. #include <boost/mysql/statement.hpp>
  10. #include <boost/mysql/string_view.hpp>
  11. #include <boost/mysql/detail/config.hpp>
  12. #include <type_traits>
  13. #ifdef BOOST_MYSQL_HAS_CONCEPTS
  14. namespace boost {
  15. namespace mysql {
  16. // Forward decls
  17. template <class... StaticRow>
  18. class static_execution_state;
  19. template <class... StaticRow>
  20. class static_results;
  21. class execution_state;
  22. class results;
  23. namespace detail {
  24. // Execution state
  25. template <class T>
  26. struct is_static_execution_state : std::false_type
  27. {
  28. };
  29. template <class... T>
  30. struct is_static_execution_state<static_execution_state<T...>> : std::true_type
  31. {
  32. };
  33. template <class T>
  34. concept execution_state_type = std::is_same_v<T, execution_state> || is_static_execution_state<T>::value;
  35. // Results
  36. template <class T>
  37. struct is_static_results : std::false_type
  38. {
  39. };
  40. template <class... T>
  41. struct is_static_results<static_results<T...>> : std::true_type
  42. {
  43. };
  44. template <class T>
  45. concept results_type = std::is_same_v<T, results> || is_static_results<T>::value;
  46. // Execution request
  47. template <class T>
  48. struct is_bound_statement_tuple : std::false_type
  49. {
  50. };
  51. template <class T>
  52. struct is_bound_statement_tuple<bound_statement_tuple<T>> : std::true_type
  53. {
  54. };
  55. template <class T>
  56. struct is_bound_statement_range : std::false_type
  57. {
  58. };
  59. template <class T>
  60. struct is_bound_statement_range<bound_statement_iterator_range<T>> : std::true_type
  61. {
  62. };
  63. template <class T>
  64. struct is_execution_request
  65. {
  66. using without_cvref = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
  67. static constexpr bool value = std::is_convertible<T, string_view>::value ||
  68. is_bound_statement_tuple<without_cvref>::value ||
  69. is_bound_statement_range<without_cvref>::value;
  70. };
  71. template <class T>
  72. concept execution_request = is_execution_request<T>::value;
  73. } // namespace detail
  74. } // namespace mysql
  75. } // namespace boost
  76. #define BOOST_MYSQL_EXECUTION_STATE_TYPE ::boost::mysql::detail::execution_state_type
  77. #define BOOST_MYSQL_RESULTS_TYPE ::boost::mysql::detail::results_type
  78. #define BOOST_MYSQL_EXECUTION_REQUEST ::boost::mysql::detail::execution_request
  79. #else
  80. #define BOOST_MYSQL_EXECUTION_STATE_TYPE class
  81. #define BOOST_MYSQL_RESULTS_TYPE class
  82. #define BOOST_MYSQL_EXECUTION_REQUEST class
  83. #endif
  84. #endif