Using std::apply with variadic packs
First parameter of std::apply
should be a functor with same arity that number of elements of the tuple, so variadic in your case:
template <typename ...Ts>
struct A : public Base{
std::tuple<Ts...> as;
A(Ts... pack) : as(pack...){}
void base_function(){
std::apply([](auto&... ts){(ts.base_function(), ...);}, as);
}
};
std::apply
is not doing what you think. It is for a passing a tuple of parameters to a function (Callable type). In other words, the tuple itself doesn't have a function called base_function
. see https://en.cppreference.com/w/cpp/utility/apply