This is an automated email from the ASF dual-hosted git repository.
syfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 8e478f57b9 [FFI] Use fold expression to simplify for_each (#18116)
8e478f57b9 is described below
commit 8e478f57b9c75c8778ccb2b32f92cc89209e6aed
Author: Twice <[email protected]>
AuthorDate: Sat Jul 5 14:20:50 2025 +0800
[FFI] Use fold expression to simplify for_each (#18116)
---
ffi/include/tvm/ffi/base_details.h | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/ffi/include/tvm/ffi/base_details.h
b/ffi/include/tvm/ffi/base_details.h
index 6b0dee462e..fb7be1a955 100644
--- a/ffi/include/tvm/ffi/base_details.h
+++ b/ffi/include/tvm/ffi/base_details.h
@@ -136,23 +136,16 @@ namespace ffi {
namespace details {
// for each iterator
-template <bool stop, std::size_t I, typename F>
struct for_each_dispatcher {
- template <typename T, typename... Args>
- static void run(const F& f, T&& value, Args&&... args) { // NOLINT(*)
- f(I, std::forward<T>(value));
- for_each_dispatcher<sizeof...(Args) == 0, (I + 1), F>::run(f,
std::forward<Args>(args)...);
+ template <typename F, typename... Args, size_t... I>
+ static void run(std::index_sequence<I...>, const F& f, Args&&... args) { //
NOLINT(*)
+ (f(I, std::forward<Args>(args)), ...);
}
};
-template <std::size_t I, typename F>
-struct for_each_dispatcher<true, I, F> {
- static void run(const F&) {} // NOLINT(*)
-};
-
template <typename F, typename... Args>
void for_each(const F& f, Args&&... args) { // NOLINT(*)
- for_each_dispatcher<sizeof...(Args) == 0, 0, F>::run(f,
std::forward<Args>(args)...);
+ for_each_dispatcher::run(std::index_sequence_for<Args...>{}, f,
std::forward<Args>(args)...);
}
/*!