From 8053a052ef29ca39bf972929c046f4c6a08c86f0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 18 Mar 2022 01:46:46 +0000 Subject: Simplify forEachField as a fold expression --- libdbpp/selectcommandUtil.impl.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/libdbpp/selectcommandUtil.impl.h b/libdbpp/selectcommandUtil.impl.h index 9ef901e..cd64e7e 100644 --- a/libdbpp/selectcommandUtil.impl.h +++ b/libdbpp/selectcommandUtil.impl.h @@ -6,19 +6,13 @@ /// @cond namespace DB { - template + template inline void - forEachField(DB::SelectCommand * sel, const Func & func, Args &&... args) + forEachField(DB::SelectCommand * sel [[maybe_unused]], auto && func, std::index_sequence) { - if constexpr (field >= std::tuple_size::value) { - (void)sel; - func(std::forward(args)...); - } - else { - typename std::tuple_element::type a; - (*sel)[field] >> a; - forEachField(sel, func, args..., a); - } + std::tuple values; + (((*sel)[I] >> std::get(values)), ...); + std::apply(func, values); } template @@ -26,7 +20,7 @@ namespace DB { SelectCommand::forEachRow(const Func & func) { while (fetch()) { - forEachField, Func, 0>(this, func); + forEachField(this, func, std::make_index_sequence {}); } } -- cgit v1.2.3