xieite::distr_args()

Defined in header <xieite/fn/distr_args.hpp>

Uniformly distributes arguments across multiple calls to a functor.


Declarations

#0
template<std::size_t arity>
constexpr void distr_args(auto&& fn, auto&&... args)
	XIEITE_ARROW_RET(xieite::unroll<(sizeof...(args) / arity)>(
		[]<std::size_t... i>(const auto& fn, const auto& args_tuple) static
			XIEITE_ARROW((..., (void)std::apply(
				fn,
				xieite::subtuple<(i * arity), ((i + 1) * arity)>(std::move(args_tuple))
			))),
		fn,
		std::forward_as_tuple(XIEITE_FWD(args)...)
	))
arity dictates how many args are to be passed to fn at a time.
Assumes that args are evenly distributable across multiple calls to fn.

#1
template<std::size_t arity, std::size_t prev = 0>
[[nodiscard]] constexpr decltype(auto) distr_args(auto&& fn, auto&&... args) noexcept(false);
Similar to #0, but with prev which dictates how many of those arguments should be recursive calls to fn (if the remaining number of args allows it).
Assumes that args are evenly distributable across multiple (possibly recursive) calls to fn. Does not specify noexcept.


Examples

#0
int main() {
	xieite::distr_args<2>(XIEITE_LIFT(xieite::dump), 1, 2, 3, 4, 5, 6);
}
Output:
1 2
3 4
5 6
[View in Compiler Explorer]

#1
int main() {
	auto fn = [](int a, int b) {
		std::println("{} + {}", a, b);
		return a + b;
	};

	int sum = xieite::distr_args<2, 1>(fn, 1, 2, 3, 4, 5);

	std::println("sum: {}", sum);
}
Output:
1 + 2
3 + 3
6 + 4
10 + 5
sum: 15
[View in Compiler Explorer]