added REPEAT_FOR_TYPES_N

This commit is contained in:
Patrick 2024-07-24 16:01:45 +02:00
parent 3413dadfae
commit dde9be29fc
1 changed files with 27 additions and 0 deletions

View File

@ -292,6 +292,26 @@ constexpr auto _repeat_for_types(auto f) {
return rets;
}
template <std::size_t _N, typename ...Ts, std::size_t N = _N - 1>
constexpr auto _repeat_for_types_n(auto f) {
std::array rets = {
[&]<typename T, std::size_t ...Ns>(std::index_sequence<Ns...>) constexpr {
return std::array { f.template operator()<T, Ns+1>()... };
}.template operator()<Ts>(std::make_index_sequence<N>())...
};
// 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<ret_val_s, sizeof...(Ts) * N> 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<N, __VA_ARGS__>(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::size_t N, typename ArgType>(std::initializer_list<ArgType> args) { \