Billing adds up fees: ints here, doubles there, both at once elsewhere. The code has a ladder of overloads sum2, sum3, sum4 (yes, literally named that). Accounting found a one-cent discrepancy and now you have an audit. One variadic template with a fold expression replaces the whole ladder.
Implement sum(args...) — a variadic function template that adds any number of arguments of any addable, possibly mixed, types. Use a C++17 fold expression, not hand-rolled recursion.
typename... Ts)(... + args) — no recursive helper, no manual base case+ on the arguments (e.g. mixing int and double yields double)(... + args) expand to for three arguments?auto / a common type rather than a fixed type?The whole body is one return: return (... + args); — a unary left fold over operator+.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.