diff --git a/cpp/4 kyu - Tuple sum.cpp b/cpp/4 kyu - Tuple sum.cpp new file mode 100644 index 0000000..f0e0b59 --- /dev/null +++ b/cpp/4 kyu - Tuple sum.cpp @@ -0,0 +1,33 @@ +#include + +static double r; + +void f(int x) +{ + r += x; +} + +void f(double x) +{ + r += x; +} + +template +void f(T t) +{ + (void) t; +} + +template +void g(Ts... ts) +{ + (f(ts), ...); +} + +template +double tuple_sum(const std::tuple& tpl) +{ + r = 0; + std::apply(g, tpl); + return r; +}