diff options
author | Marco Bubke <marco.bubke@qt.io> | 2023-05-26 22:39:02 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2023-05-30 09:59:19 +0000 |
commit | 2981feefd718123dcbecbb3183e77fb1d3f29129 (patch) | |
tree | 7723f76c39a83c9670dd6a27af505c43b0cb734f /src/libs/sqlite | |
parent | 15062522a38a75e0227b167606ab534e8dd22333 (diff) |
Sqlite: Improve readCallback
There are many callback which do not control the flow and want to be
called for all steps. For that case we assume that a callback without a
return value will continue always.
Change-Id: I706123f2c425ac8c937d4d60ab977dae5ea9b030
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
Diffstat (limited to 'src/libs/sqlite')
-rw-r--r-- | src/libs/sqlite/sqlitebasestatement.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/libs/sqlite/sqlitebasestatement.h b/src/libs/sqlite/sqlitebasestatement.h index 1178b97f3a..35db04e3ed 100644 --- a/src/libs/sqlite/sqlitebasestatement.h +++ b/src/libs/sqlite/sqlitebasestatement.h @@ -496,16 +496,30 @@ private: return createValue<ResultType>(std::make_integer_sequence<int, ResultCount>{}); } + template<typename Callable, typename... Arguments> + CallbackControl invokeCallable(Callable &&callable, Arguments &&...arguments) + { + if constexpr (std::is_void_v<std::invoke_result_t<Callable, Arguments...>>) { + std::invoke(std::forward<Callable>(callable), std::forward<Arguments>(arguments)...); + return CallbackControl::Continue; + } else { + return std::invoke(std::forward<Callable>(callable), + std::forward<Arguments>(arguments)...); + } + } + template<typename Callable, int... ColumnIndices> CallbackControl callCallable(Callable &&callable, std::integer_sequence<int, ColumnIndices...>) { - return std::invoke(callable, ValueGetter(*this, ColumnIndices)...); + return invokeCallable(std::forward<Callable>(callable), + ValueGetter(*this, ColumnIndices)...); } template<typename Callable> CallbackControl callCallable(Callable &&callable) { - return callCallable(callable, std::make_integer_sequence<int, ResultCount>{}); + return callCallable(std::forward<Callable>(callable), + std::make_integer_sequence<int, ResultCount>{}); } void setMaximumResultCount(std::size_t count) |