From e730fee77a200415c1b9754746dee0d1aa4cf8db Mon Sep 17 00:00:00 2001 From: Vittorio Romeo Date: Sun, 19 Mar 2023 14:26:15 +0100 Subject: [PATCH 1/3] Simplify reverse tuple iteration --- dev/functional/index_sequence_util.h | 31 ------------------------- dev/tuple_helper/tuple_iteration.h | 3 ++- include/sqlite_orm/sqlite_orm.h | 34 ++-------------------------- 3 files changed, 4 insertions(+), 64 deletions(-) diff --git a/dev/functional/index_sequence_util.h b/dev/functional/index_sequence_util.h index 061627247..73a355ec9 100644 --- a/dev/functional/index_sequence_util.h +++ b/dev/functional/index_sequence_util.h @@ -17,37 +17,6 @@ namespace sqlite_orm { return I; } -#ifdef SQLITE_ORM_RELAXED_CONSTEXPR_SUPPORTED - /** - * Reorder the values of an index_sequence according to the positions from a second sequence. - */ - template - SQLITE_ORM_CONSTEVAL auto reorder_index_sequence(std::index_sequence, - std::index_sequence) { - constexpr std::array values{Value...}; - return std::index_sequence{}; - } - - template - SQLITE_ORM_CONSTEVAL std::index_sequence reorder_index_sequence(std::index_sequence, - std::index_sequence) { - return {}; - } - - inline SQLITE_ORM_CONSTEVAL std::index_sequence<> reorder_index_sequence(std::index_sequence<>, - std::index_sequence<>) { - return {}; - } - - /** - * Reverse the values of an index_sequence. - */ - template - SQLITE_ORM_CONSTEVAL auto reverse_index_sequence(std::index_sequence) { - return reorder_index_sequence(std::index_sequence{}, std::make_index_sequence{}); - } -#endif - template struct flatten_idxseq { using type = std::index_sequence<>; diff --git a/dev/tuple_helper/tuple_iteration.h b/dev/tuple_helper/tuple_iteration.h index cb37f7cbe..26b834f51 100644 --- a/dev/tuple_helper/tuple_iteration.h +++ b/dev/tuple_helper/tuple_iteration.h @@ -33,7 +33,8 @@ namespace sqlite_orm { template void iterate_tuple(const Tpl& tpl, std::index_sequence, L&& lambda) { if constexpr(reversed) { - iterate_tuple(tpl, reverse_index_sequence(std::index_sequence{}), std::forward(lambda)); + int sink; + ((lambda(std::get(tpl)), sink) = ... = 0); } else { (lambda(std::get(tpl)), ...); } diff --git a/include/sqlite_orm/sqlite_orm.h b/include/sqlite_orm/sqlite_orm.h index 10e526f6b..7b3075a7c 100644 --- a/include/sqlite_orm/sqlite_orm.h +++ b/include/sqlite_orm/sqlite_orm.h @@ -1128,37 +1128,6 @@ namespace sqlite_orm { return I; } -#ifdef SQLITE_ORM_RELAXED_CONSTEXPR_SUPPORTED - /** - * Reorder the values of an index_sequence according to the positions from a second sequence. - */ - template - SQLITE_ORM_CONSTEVAL auto reorder_index_sequence(std::index_sequence, - std::index_sequence) { - constexpr std::array values{Value...}; - return std::index_sequence{}; - } - - template - SQLITE_ORM_CONSTEVAL std::index_sequence reorder_index_sequence(std::index_sequence, - std::index_sequence) { - return {}; - } - - inline SQLITE_ORM_CONSTEVAL std::index_sequence<> reorder_index_sequence(std::index_sequence<>, - std::index_sequence<>) { - return {}; - } - - /** - * Reverse the values of an index_sequence. - */ - template - SQLITE_ORM_CONSTEVAL auto reverse_index_sequence(std::index_sequence) { - return reorder_index_sequence(std::index_sequence{}, std::make_index_sequence{}); - } -#endif - template struct flatten_idxseq { using type = std::index_sequence<>; @@ -9574,7 +9543,8 @@ namespace sqlite_orm { template void iterate_tuple(const Tpl& tpl, std::index_sequence, L&& lambda) { if constexpr(reversed) { - iterate_tuple(tpl, reverse_index_sequence(std::index_sequence{}), std::forward(lambda)); + int sink; + ((lambda(std::get(tpl)), sink) = ... = 0); } else { (lambda(std::get(tpl)), ...); } From 1dc9cdcbdf469960e12476ef6cc0338eaa7a56ac Mon Sep 17 00:00:00 2001 From: Vittorio Romeo Date: Mon, 20 Mar 2023 01:49:19 +0100 Subject: [PATCH 2/3] Apply review suggestions --- dev/functional/index_sequence_util.h | 3 --- include/sqlite_orm/sqlite_orm.h | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/dev/functional/index_sequence_util.h b/dev/functional/index_sequence_util.h index 73a355ec9..b13343663 100644 --- a/dev/functional/index_sequence_util.h +++ b/dev/functional/index_sequence_util.h @@ -3,9 +3,6 @@ #include // std::index_sequence, std::make_index_sequence #include "../functional/cxx_universal.h" -#ifdef SQLITE_ORM_RELAXED_CONSTEXPR_SUPPORTED -#include -#endif namespace sqlite_orm { namespace internal { diff --git a/include/sqlite_orm/sqlite_orm.h b/include/sqlite_orm/sqlite_orm.h index 7b3075a7c..4dcc1bcd8 100644 --- a/include/sqlite_orm/sqlite_orm.h +++ b/include/sqlite_orm/sqlite_orm.h @@ -1114,10 +1114,6 @@ namespace sqlite_orm { // #include "../functional/cxx_universal.h" -#ifdef SQLITE_ORM_RELAXED_CONSTEXPR_SUPPORTED -#include -#endif - namespace sqlite_orm { namespace internal { /** @@ -9543,6 +9539,7 @@ namespace sqlite_orm { template void iterate_tuple(const Tpl& tpl, std::index_sequence, L&& lambda) { if constexpr(reversed) { + // nifty fold expression trick: make use of guaranteed right-to-left evaluation order when folding over operator= int sink; ((lambda(std::get(tpl)), sink) = ... = 0); } else { From e64e23b297d5fb932499fb50d66d1296c3404f06 Mon Sep 17 00:00:00 2001 From: Vittorio Romeo Date: Mon, 20 Mar 2023 01:51:51 +0100 Subject: [PATCH 3/3] Apply review suggestions --- dev/tuple_helper/tuple_iteration.h | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tuple_helper/tuple_iteration.h b/dev/tuple_helper/tuple_iteration.h index 26b834f51..4d0a971fc 100644 --- a/dev/tuple_helper/tuple_iteration.h +++ b/dev/tuple_helper/tuple_iteration.h @@ -33,6 +33,7 @@ namespace sqlite_orm { template void iterate_tuple(const Tpl& tpl, std::index_sequence, L&& lambda) { if constexpr(reversed) { + // nifty fold expression trick: make use of guaranteed right-to-left evaluation order when folding over operator= int sink; ((lambda(std::get(tpl)), sink) = ... = 0); } else {