Template for function with N inputs
06:37 30 Oct 2025

If it's possible, I would like to define a macro that would take number of arguments in function template ARGS_COUNT and make a template with all argument types being enumerated and output being common type. For example, if it is defined as

TEMPLATE_COMMON_FLOAT(N) /* ...definition...*/

then

TEMPLATE_COMMON_FLOAT(4)
foo(F0 a, F1 b, F2 c, F3 d) { /*...*/ }

should expand to

template 
  requires std::is_floating_point_v && std::is_floating_point_v && std::is_floating_point_v && std::is_floating_point_v
std::common_type_t foo(F0 a, F1 b, F2 c, F3 d) { /*...*/ }

I want this, since I would like to refer to Fi sometimes, instead of bloating function definition with std::floating_point auto and decltypeing after.

c++ templates c-preprocessor