Hi,
given the following function signature
pub fn process(S: type, T: type, samples: [] const S) void {
//process samples using T as result type
}
and an application, where the user can choose among a set of types for both S and T independently through command line arguments. What options are available to select the types at runtime?
At the moment I have two enums that provide the possible options the user can choose for both types, e.g. like these:
const SampleType = enum { i16, i32};
const OutputType = enum { f32, f64};
and then have nested switches in function wrappers
pub SwitchOnInputType(s: InputType, t: OutputType, samples: [] const S) void {
switch(s) {
.i16 => SwitchOnOutputType(i16, t, samples),
.i32 => SwitchOnOutputType(i32, t, samples),
}
pub SwitchOnOutputType(S: type, t: OutputType, samples: [] const S) void {
switch(t) {
.f32 => process(S, f32, samples),
.f64 => process(S, f64, samples),
}
}
How would you implement this? What are possible pros/cons?
EDIT: somehow I messed up the code sample for the function wrappers.