Calling a lambda for each nth argument of multiple tuples?

I am trying to write a code that invokes a lambda with input arguments extracted from a variadic set of tuples. However, my attempt does not compile:

#include <iostream>
#include <tuple>
#include <utility>
#include <type_traits>

template <typename ...>
struct first_of;

template <typename T, typename ... Args>
struct first_of<T, Args...> {
    using type = std::decay_t<T>;
};

template <typename T>
struct first_of<T> {
    using type = std::decay_t<T>;
};

template <typename ... T>
using first_of_t = typename first_of<T...>::type;

template <typename Fn, typename... Tuples, std::size_t... Idxs>
void run_impl(Fn&& fn, std::index_sequence<Idxs...>, Tuples... t) {
  auto temp = {(fn(std::get<Idxs>(t)...), true)...};
  (void)temp;
}

template <typename Fn, typename... Tuples>
void run(Fn&& fn, Tuples&&... tuples) {
  run_impl(std::forward<Fn>(fn), std::make_index_sequence<std::tuple_size<first_of_t<Tuples...>>::value>{}, std::forward<Tuples>(tuples)...);
}

int main() {
    auto a = std::make_tuple(1, 2.34, "one");
    auto b = std::make_tuple(32, 5.34, "two");

    auto print = [](auto& f, auto& g) { std::cout << f << ", " << g << std::endl; };
    run(print, a, b);
}

I am expecting the following output:

1, 32
2.34, 5.34
one, two

I am using c++14, so unfortunately, no fold expressions.
Here is the godbolt link to the code: https://godbolt.org/z/G19n5z

Source: Windows Questions C++

LEAVE A COMMENT