From dde9be29fc575b35296b8929d9e5241e35be14a0 Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 24 Jul 2024 16:01:45 +0200 Subject: [PATCH] added REPEAT_FOR_TYPES_N --- test/common_helper/test.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/common_helper/test.hpp b/test/common_helper/test.hpp index 2242e30..6b89ad4 100644 --- a/test/common_helper/test.hpp +++ b/test/common_helper/test.hpp @@ -292,6 +292,26 @@ constexpr auto _repeat_for_types(auto f) { return rets; } +template +constexpr auto _repeat_for_types_n(auto f) { + std::array rets = { + [&](std::index_sequence) constexpr { + return std::array { f.template operator()()... }; + }.template operator()(std::make_index_sequence())... + }; + // Clion does not accept this as a constant expression + // even though it compiles and works as intended + //return rets | std::ranges::views::join; + std::array arr; + auto arr_it = std::begin(arr); + for (auto&& rp : rets) { + for (ret_val_s& r : rp) { + *(arr_it++) = r; + } + } + return arr; +} + #define REPEAT_FOR_TYPES(func, ...) { \ auto r = _repeat_for_types<__VA_ARGS__>(func); \ auto it = std::ranges::find_if(r, [](auto&& e) constexpr { return e.val == ReturnCode::FAILED; }); \ @@ -300,6 +320,13 @@ constexpr auto _repeat_for_types(auto f) { } \ } static_assert(true, "") +#define REPEAT_FOR_TYPES_N(func, N, ...) { \ + auto r = _repeat_for_types_n(func); \ + auto it = std::ranges::find_if(r, [](auto&& e) constexpr { return e.val == ReturnCode::FAILED; }); \ + if (it != std::ranges::end(r)) { \ + return *it; \ + } \ +} static_assert(true, "") #define CREATE_FROM_IL(type, il, len) \ ([](std::initializer_list args) { \