From f7e76cc9f12396477747f87e5319522a97b6833a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 30 Jun 2022 12:22:14 -0700 Subject: [PATCH] ircd::json: Reuse ircd::util abstract tuple tools. --- include/ircd/json/tuple/for_each.h | 56 ++++++----------------------- include/ircd/json/tuple/rfor_each.h | 50 +++++--------------------- 2 files changed, 18 insertions(+), 88 deletions(-) diff --git a/include/ircd/json/tuple/for_each.h b/include/ircd/json/tuple/for_each.h index 7ec6773f8..f0ec4c8ce 100644 --- a/include/ircd/json/tuple/for_each.h +++ b/include/ircd/json/tuple/for_each.h @@ -14,66 +14,30 @@ namespace ircd { namespace json { -template inline enable_if_tuple for_each(const tuple &t, function&& f) { - if constexpr(i < size()) + return util::for_each(t, [&f] + (const auto &prop) { - using closure_result = std::invoke_result_t - < - decltype(f), decltype(key(t)), decltype(val(t)) - >; - - constexpr bool terminable - { - std::is_same() - }; - - if constexpr(terminable) - { - if(!f(key(t), val(t))) - return false; - } - else f(key(t), val(t)); - - return for_each(t, std::forward(f)); - } - else return true; + return f(prop.key, prop.value); + }); } -template inline enable_if_tuple for_each(tuple &t, function&& f) { - if constexpr(i < size()) + return util::for_each(t, [&f] + (auto &prop) { - using closure_result = std::invoke_result_t - < - decltype(f), decltype(key(t)), decltype(val(t)) - >; - - constexpr bool terminable - { - std::is_same() - }; - - if constexpr(terminable) - { - if(!f(key(t), val(t))) - return false; - } - else f(key(t), val(t)); - - return for_each(t, std::forward(f)); - } - else return true; + return f(prop.key, prop.value); + }); } template rfor_each(const tuple &t, function&& f) { - if constexpr(i >= 0) + return util::rfor_each(t, [&f] + (const auto &prop) { - using closure_result = std::invoke_result_t - < - decltype(f), decltype(key(t)), decltype(val(t)) - >; - - constexpr bool terminable - { - std::is_same() - }; - - if constexpr(terminable) - { - if(!f(key(t), val(t))) - return false; - } - else f(key(t), val(t)); - - return rfor_each(t, std::forward(f)); - } - else return true; + return f(prop.key, prop.value); + }); } template rfor_each(tuple &t, function&& f) { - if constexpr(i >= 0) + return util::rfor_each(t, [&f] + (auto &prop) { - using closure_result = std::invoke_result_t - < - decltype(f), decltype(key(t)), decltype(val(t)) - >; - - constexpr bool terminable - { - std::is_same() - }; - - if constexpr(terminable) - { - if(!f(key(t), val(t))) - return false; - } - else f(key(t), val(t)); - - return rfor_each(t, std::forward(f)); - } - else return true; + return f(prop.key, prop.value); + }); } } // namespace json