What is the best way to write the readvals function in the following code without using Boost? Basically, it should get a tuple, call a specific function of it's elemets and return the generated results as a tuple again.
Is there any C++0X-based Functor definition library for tuples?
template <class T>
struct A
{
A(T _val):val(_val){}
T ret() {return val;}
T val;
};
template <typename... ARGS>
std::tuple<ARGS...> readvals(std::tuple<A<ARGS>...> targ)
{
//???
}
int main(int argc, char **argv)
{
A<int> ai = A<int>(5);
A<char> ac = A<char>('c');
A<double> ad = A<double>(0.5);
std::tuple<A<int>,A<char>,A<double>> at = std::make_tuple(ai,ac,ad);
// assuming proper overloading of "<<" for tuples exists
std::cout << readvals<int,char,double>(at) << std::endl;
// I expect something like (5, c, 0.5) in the output
return 0;
}
I have found questions on SO which deal partly with this problem (tuple unpacking, iterating over tuple elements, etc.), but it seems to me that there should be an easier solution compared to putting together all such solutions.