what about:
g(std::get<Indices>(t)...)
where Indices is a parameter pack of indices.
Creating such an indices pack can be created with the
package_range_c template as shown here:
https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates/l...
Warning, NOT TESTED.
HTH.
-Larry
Thanks. It seems to do more than I need but it definitely helped
thinking about the problem.
First, create a level of indirection between g() and f(),
f_impl(indices<I,Values...>, tuple). Second, Values... is mapped from
Args... using a straightforward recursion.
Below is a solution that compiled with GCC4.4 with flag -std=c++0x
#include <cstddef>
#include <tuple>
#include <iostream>
template<typename ...Args> struct pack_holder{};
template<typename I, I...Values> struct indices{};
namespace impl{
template<typename Indices,typename Pack> struct args_to_indices{};
template<typename I, I...Tail, typename T, typename... Rest>
struct args_to_indices<
{
typedef typename impl::args_to_indices<
indices said:
};
template<typename I, I...Tail>
struct args_to_indices<
indices said:
typedef indices<I, Tail...> type;
};
}// impl
template<typename I,typename...Args>
struct args_to_indices : impl::args_to_indices<
indices said:
void g(){}
template<typename T,typename...Args>
void g(T&& t, Args&&...args)
{
std::cout << t << ' ';
g( args... );
}
template<typename I,I ...Values, typename T>
void f_impl(indices<I, Values...>, T const& t )
{
g( std::get<Values>( t )...);
}
template<typename ...Args>
void f( std::tuple<Args...> const& t )
{
typedef int int_;
typedef typename args_to_indices<int_,Args...>::type indices_;
f_impl(indices_(), t);
}
int main(){
typedef std::tuple<int, const char*, double> tuple_;
tuple_ t(12, "Hello", 43.56);
f( t ); // outputs 12 "Hello" 43.56
return 0;
}