My question is in the code:
template
struct TupleOfVectors {
std::tuple...> tuple;
void do_something_t
I was testing with tuples and metaprograming and found the current thread. I think my work can inspire someone else although I like the solution of @Andy.
Anyway, just get fun!
#include
#include
#include
#include
#include
template
typename std::enable_if< I != std::tuple_size::value, void >::type
for_each(const Tuple& tuple, Func&& func)
{
func(std::get(tuple));
for_each(tuple, func);
}
template
typename std::enable_if< I == std::tuple_size::value, void >::type
for_each(const Tuple& tuple, Func&& func)
{
// do nothing
}
struct print
{
template
void operator () (T&& t)
{
std::cout << t << std::endl;
}
};
template
void test(Params&& ... params)
{
int sz = sizeof...(params);
std::tuple values(std::forward(params)...);
for_each(values, print() );
}
class MyClass
{
public:
MyClass(const std::string& text)
: m_text(text)
{
}
friend std::ostream& operator <<(std::ostream& stream, const MyClass& myClass)
{
stream << myClass.m_text;
return stream;
}
private:
std::string m_text;
};
int main()
{
test(1, "hello", 3.f, 4, MyClass("I don't care") );
}