namespace details {
template <std::size_t I = 0, typename Tuple, typename Function, typename... Args>
typename std::enable_if<I == std::tuple_size<Tuple>::value, void>::type ForEach(Tuple &t, Function f, Args &... args) {}
template <std::size_t I = 0, typename Tuple, typename Function, typename... Args>
typename std::enable_if<(I < std::tuple_size<Tuple>::value), void>::type ForEach(Tuple &t, Function f, Args &... args) {
f(std::get<I>(t), args...);
ForEach<I + 1>(t, f, args...);
}
}
An implementation for ForEach functionality for all types of a tuple is above. It calls f(tuple_type, args...)
However I want something like tuple_type.f(args...) where f and args are template arguments.
f would be a member function of all the types in the tuple, taking args... as arguments.
template <typename... Types>
class TupleManager {
std::tuple<Types...> t;
template <typename Function, typename... Args>
void ForEach(Function f, Args& ... args) {
details::ForEach<>(t, f, args...);
}
}
Aucun commentaire:
Enregistrer un commentaire