|
29 | 29 | #include <tvm/ffi/endian.h> |
30 | 30 |
|
31 | 31 | #include <cstddef> |
32 | | -#include <type_traits> |
33 | 32 | #include <utility> |
34 | 33 |
|
35 | 34 | #if defined(_MSC_VER) |
@@ -136,32 +135,14 @@ namespace tvm { |
136 | 135 | namespace ffi { |
137 | 136 | namespace details { |
138 | 137 |
|
139 | | -// a dependent-name version of false, for static_assert |
140 | | -template <typename> |
141 | | -inline constexpr bool always_false = false; |
142 | | - |
143 | 138 | // for each iterator |
144 | 139 | struct for_each_dispatcher { |
145 | 140 | template <typename F, typename... Args, size_t... I> |
146 | 141 | static void run(std::index_sequence<I...>, const F& f, Args&&... args) { // NOLINT(*) |
147 | | - if constexpr (std::conjunction_v< |
148 | | - std::is_invocable<F, std::integral_constant<size_t, I>, Args>...>) { |
149 | | - (f(std::integral_constant<size_t, I>{}, std::forward<Args>(args)), ...); |
150 | | - } else if constexpr (std::conjunction_v<std::is_invocable<F, size_t, Args>...>) { |
151 | | - (f(I, std::forward<Args>(args)), ...); |
152 | | - } else if constexpr (std::conjunction_v<std::is_invocable<F, Args>...>) { |
153 | | - (f(std::forward<Args>(args)), ...); |
154 | | - } else { |
155 | | - static_assert(always_false<F>, "The function is not invocable with the provided arguments"); |
156 | | - } |
| 142 | + (f(I, std::forward<Args>(args)), ...); |
157 | 143 | } |
158 | 144 | }; |
159 | 145 |
|
160 | | -// Three kinds of function F are acceptable in `for_each`: |
161 | | -// 1. F(size_t, Arg): argument with its index |
162 | | -// 2. F(Arg): just the argument |
163 | | -// 3. F(std::integral_constant<size_t, I>, Arg): argument with its constexpr index |
164 | | -// The third one can make the index available in template arguments and `if constexpr`. |
165 | 146 | template <typename F, typename... Args> |
166 | 147 | void for_each(const F& f, Args&&... args) { // NOLINT(*) |
167 | 148 | for_each_dispatcher::run(std::index_sequence_for<Args...>{}, f, std::forward<Args>(args)...); |
|
0 commit comments