Example
fn fooA1B1(_: std.mem.Allocator) void {
const input_a = comptime get_a(1);
const input_b = comptime get_b(1);
bar(input_a, input_b);
}
fn fooA1B2(_: std.mem.Allocator) void {
const input_a = comptime get_a(1);
const input_b = comptime get_b(2);
bar(input_a, input_b);
}
fn fooA2B1(_: std.mem.Allocator) void {
const input_a = comptime get_a(2);
const input_b = comptime get_b(1);
bar(input_a, input_b);
}
...
Instead, I would like something like this:
const FooAxBy: type = fn(std.mem.Allocator) void;
fn make_fooAxBy(x: comptime_int, y: comptime_int) FooAxBy {
const input_a = comptime get_a(x);
const input_b = comptime get_b(y);
// madeup syntax
return fn foo(_: std.mem.Allocator) void {
bar(input_a, input_b);
}
}
Context
I am running benchmarks with Zbench, and since it expects the functions I benchmark to have a certain type signature (i.e. receives an allocator and nothing else), I am creating a lot of wrapper functions since I want to benchmark my code on a lot of different types of inputs.
Question
Is it possible to make and return functions like I have shown above?
Is there another way to reduce boilerplate in my situation? (avoid XY problem)