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
10#ifndef BOOST_UNORDERED_DETAIL_CONCURRENT_STATIC_ASSERTS_HPP
11#define BOOST_UNORDERED_DETAIL_CONCURRENT_STATIC_ASSERTS_HPP
12
13#include <boost/config.hpp>
14#include <boost/mp11/algorithm.hpp>
15#include <boost/mp11/list.hpp>
16
17#include <functional>
18#include <iterator>
19#include <type_traits>
20
21#define BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE(F) \
22 static_assert(boost::unordered::detail::is_invocable<F, value_type&>::value, \
23 "The provided Callable must be invocable with value_type&");
24
25#define BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) \
26 static_assert( \
27 boost::unordered::detail::is_invocable<F, value_type const&>::value, \
28 "The provided Callable must be invocable with value_type const&");
29
30#if BOOST_CXX_VERSION >= 202002L
31
32#define BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(P) \
33 static_assert(!std::is_base_of<std::execution::parallel_unsequenced_policy, \
34 ExecPolicy>::value, \
35 "ExecPolicy must be sequenced."); \
36 static_assert( \
37 !std::is_base_of<std::execution::unsequenced_policy, ExecPolicy>::value, \
38 "ExecPolicy must be sequenced.");
39
40#else
41
42#define BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(P) \
43 static_assert(!std::is_base_of<std::execution::parallel_unsequenced_policy, \
44 ExecPolicy>::value, \
45 "ExecPolicy must be sequenced.");
46#endif
47
48#define BOOST_UNORDERED_DETAIL_COMMA ,
49
50#define BOOST_UNORDERED_DETAIL_LAST_ARG(Arg, Args) \
51 mp11::mp_back<mp11::mp_list<Arg BOOST_UNORDERED_DETAIL_COMMA Args> >
52
53#define BOOST_UNORDERED_STATIC_ASSERT_LAST_ARG_INVOCABLE(Arg, Args) \
54 BOOST_UNORDERED_STATIC_ASSERT_INVOCABLE( \
55 BOOST_UNORDERED_DETAIL_LAST_ARG(Arg, Args))
56
57#define BOOST_UNORDERED_STATIC_ASSERT_LAST_ARG_CONST_INVOCABLE(Arg, Args) \
58 BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE( \
59 BOOST_UNORDERED_DETAIL_LAST_ARG(Arg, Args))
60
61namespace boost {
62 namespace unordered {
63 namespace detail {
64 template <class F, class... Args>
65 struct is_invocable
66 : std::is_constructible<std::function<void(Args...)>,
67 std::reference_wrapper<typename std::remove_reference<F>::type> >
68 {
69 };
70
71 } // namespace detail
72
73 } // namespace unordered
74
75} // namespace boost
76
77#if defined(BOOST_NO_CXX20_HDR_CONCEPTS)
78#define BOOST_UNORDERED_STATIC_ASSERT_FWD_ITERATOR(Iterator) \
79 static_assert( \
80 std::is_base_of< \
81 std::forward_iterator_tag, \
82 typename std::iterator_traits<Iterator>::iterator_category>::value, \
83 "The provided iterator must be at least forward");
84#else
85#define BOOST_UNORDERED_STATIC_ASSERT_FWD_ITERATOR(Iterator) \
86 static_assert(std::forward_iterator<Iterator>, \
87 "The provided iterator must be at least forward");
88
89#endif
90
91#define BOOST_UNORDERED_STATIC_ASSERT_KEY_COMPATIBLE_ITERATOR(Iterator) \
92 static_assert( \
93 std::is_same< \
94 typename std::iterator_traits<Iterator>::value_type, \
95 key_type>::value || \
96 detail::are_transparent< \
97 typename std::iterator_traits<Iterator>::value_type, \
98 hasher, key_equal>::value, \
99 "The provided iterator must dereference to a compatible key value");
100
101#define BOOST_UNORDERED_STATIC_ASSERT_BULK_VISIT_ITERATOR(Iterator) \
102 BOOST_UNORDERED_STATIC_ASSERT_FWD_ITERATOR(Iterator) \
103 BOOST_UNORDERED_STATIC_ASSERT_KEY_COMPATIBLE_ITERATOR(Iterator)
104
105#endif // BOOST_UNORDERED_DETAIL_CONCURRENT_STATIC_ASSERTS_HPP
106

source code of boost/libs/unordered/include/boost/unordered/detail/concurrent_static_asserts.hpp