summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-03-18 01:46:46 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-03-18 01:46:46 +0000
commit8053a052ef29ca39bf972929c046f4c6a08c86f0 (patch)
tree34c19ab12e0f308332db7022a0dd7edbe1dfbb11
parentLots of pass by value and perfect forwarding optimisations (diff)
downloadlibdbpp-8053a052ef29ca39bf972929c046f4c6a08c86f0.tar.bz2
libdbpp-8053a052ef29ca39bf972929c046f4c6a08c86f0.tar.xz
libdbpp-8053a052ef29ca39bf972929c046f4c6a08c86f0.zip
Simplify forEachField as a fold expression
-rw-r--r--libdbpp/selectcommandUtil.impl.h18
1 files 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<typename Fields, typename Func, unsigned int field, typename... Fn, typename... Args>
+ template<typename... Fn, std::size_t... I>
inline void
- forEachField(DB::SelectCommand * sel, const Func & func, Args &&... args)
+ forEachField(DB::SelectCommand * sel [[maybe_unused]], auto && func, std::index_sequence<I...>)
{
- if constexpr (field >= std::tuple_size<Fields>::value) {
- (void)sel;
- func(std::forward<Args>(args)...);
- }
- else {
- typename std::tuple_element<field, Fields>::type a;
- (*sel)[field] >> a;
- forEachField<Fields, Func, field + 1, Fn...>(sel, func, args..., a);
- }
+ std::tuple<Fn...> values;
+ (((*sel)[I] >> std::get<I>(values)), ...);
+ std::apply(func, values);
}
template<typename... Fn, typename Func>
@@ -26,7 +20,7 @@ namespace DB {
SelectCommand::forEachRow(const Func & func)
{
while (fetch()) {
- forEachField<std::tuple<Fn...>, Func, 0>(this, func);
+ forEachField<Fn...>(this, func, std::make_index_sequence<sizeof...(Fn)> {});
}
}