Skip to content

Commit

Permalink
Create 4 kyu - Tuple sum.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
freedan42x authored Feb 18, 2023
1 parent f73bc83 commit d1844d8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cpp/4 kyu - Tuple sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <tuple>

static double r;

void f(int x)
{
r += x;
}

void f(double x)
{
r += x;
}

template <typename T>
void f(T t)
{
(void) t;
}

template <typename... Ts>
void g(Ts... ts)
{
(f(ts), ...);
}

template <typename... Ts>
double tuple_sum(const std::tuple<Ts...>& tpl)
{
r = 0;
std::apply(g<Ts...>, tpl);
return r;
}

0 comments on commit d1844d8

Please sign in to comment.