concurrent_static_asserts.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright 2023 Christian Mazakas.
  2. * Copyright 2023 Joaquin M Lopez Munoz.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. *
  7. * See https://www.boost.org/libs/unordered for library home page.
  8. */
  9. #ifndef BOOST_UNORDERED_DETAIL_CONCURRENT_STATIC_ASSERTS_HPP
  10. #define BOOST_UNORDERED_DETAIL_CONCURRENT_STATIC_ASSERTS_HPP
  11. #include <boost/config.hpp>
  12. #include <boost/mp11/algorithm.hpp>
  13. #include <boost/mp11/list.hpp>
  14. #include <functional>
  15. #include <iterator>
  16. #include <type_traits>
  17. #define BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F) \
  18. static_assert(boost::unordered::detail::is_invocable<F, value_type&>::value, \
  19. "The provided Callable must be invocable with value_type&");
  20. #define BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) \
  21. static_assert( \
  22. boost::unordered::detail::is_invocable<F, value_type const&>::value, \
  23. "The provided Callable must be invocable with value_type const&");
  24. #if BOOST_CXX_VERSION >= 202002L
  25. #define BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(P) \
  26. static_assert(!std::is_base_of<std::execution::parallel_unsequenced_policy, \
  27. ExecPolicy>::value, \
  28. "ExecPolicy must be sequenced."); \
  29. static_assert( \
  30. !std::is_base_of<std::execution::unsequenced_policy, ExecPolicy>::value, \
  31. "ExecPolicy must be sequenced.");
  32. #else
  33. #define BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(P) \
  34. static_assert(!std::is_base_of<std::execution::parallel_unsequenced_policy, \
  35. ExecPolicy>::value, \
  36. "ExecPolicy must be sequenced.");
  37. #endif
  38. #define BOOST_UNORDERED_DETAIL_COMMA ,
  39. #define BOOST_UNORDERED_DETAIL_LAST_ARG(Arg, Args) \
  40. mp11::mp_back<mp11::mp_list<Arg BOOST_UNORDERED_DETAIL_COMMA Args> >
  41. #define BOOST_UNORDERED_STATIC_ASSERT_LAST_ARG_INVOCABLE(Arg, Args) \
  42. BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE( \
  43. BOOST_UNORDERED_DETAIL_LAST_ARG(Arg, Args))
  44. #define BOOST_UNORDERED_STATIC_ASSERT_LAST_ARG_CONST_INVOCABLE(Arg, Args) \
  45. BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE( \
  46. BOOST_UNORDERED_DETAIL_LAST_ARG(Arg, Args))
  47. namespace boost {
  48. namespace unordered {
  49. namespace detail {
  50. template <class F, class... Args>
  51. struct is_invocable
  52. : std::is_constructible<std::function<void(Args...)>,
  53. std::reference_wrapper<typename std::remove_reference<F>::type> >
  54. {
  55. };
  56. } // namespace detail
  57. } // namespace unordered
  58. } // namespace boost
  59. #if defined(BOOST_NO_CXX20_HDR_CONCEPTS)
  60. #define BOOST_UNORDERED_STATIC_ASSERT_FWD_ITERATOR(Iterator) \
  61. static_assert( \
  62. std::is_base_of< \
  63. std::forward_iterator_tag, \
  64. typename std::iterator_traits<Iterator>::iterator_category>::value, \
  65. "The provided iterator must be at least forward");
  66. #else
  67. #define BOOST_UNORDERED_STATIC_ASSERT_FWD_ITERATOR(Iterator) \
  68. static_assert(std::forward_iterator<Iterator>, \
  69. "The provided iterator must be at least forward");
  70. #endif
  71. #define BOOST_UNORDERED_STATIC_ASSERT_KEY_COMPATIBLE_ITERATOR(Iterator) \
  72. static_assert( \
  73. std::is_same< \
  74. typename std::iterator_traits<Iterator>::value_type, \
  75. key_type>::value || \
  76. detail::are_transparent< \
  77. typename std::iterator_traits<Iterator>::value_type, \
  78. hasher, key_equal>::value, \
  79. "The provided iterator must dereference to a compatible key value");
  80. #define BOOST_UNORDERED_STATIC_ASSERT_BULK_VISIT_ITERATOR(Iterator) \
  81. BOOST_UNORDERED_STATIC_ASSERT_FWD_ITERATOR(Iterator) \
  82. BOOST_UNORDERED_STATIC_ASSERT_KEY_COMPATIBLE_ITERATOR(Iterator)
  83. #endif // BOOST_UNORDERED_DETAIL_CONCURRENT_STATIC_ASSERTS_HPP