Re: C++0x: variadic template puzzle
SG <s.gesem...@gmail.com> wrote:
[...]
template<typename Func, typename... Args>
inline void tuple_forward(Func && f, tuple<Args...> && args)
{
typedef invoke_helper<0,1,2,...,(sizeof...(Args)-1)> ih;
ih::doit( forward<Func>(f) , move(args) );
// Note: "args" is always an rvalue reference. There is
// no reference collapsing involved.
}
I havn't yet been able to come up with a solution for the "ih"-
typedef. Obviously the line is ill-formed.
I think I solved it. It required quite a bit of TMP noise, though:
template< typename, typename >
struct concat;
template< int... I1, int... I2 >
struct concat< invoke_helper<T1...>, invoke_helper<T2...> >
{
typedef invoke_helper<T1...,T2...> type;
};
template< int Count, int Start = 0 >
struct make_helper
{
static const int Half1 = Count/2;
static const int Half2 = Count-Half1;
static const int Center = Start + Half1;
typedef typename concat<
typename make_helper<Half1,Start>::type,
typename make_helper<Half2,Center>::type
>::type type;
};
template<int Start>
struct make_helper<0,Start>
{ typedef invoke_helper<> type; };
template<int Start>
struct make_helper<1,Start>
{ typedef invoke_helper<Start> type; };
template<typename Func, typename... Args>
inline void tuple_forward(Func && f, tuple<Args...> && args)
{
typedef typename make_helper<sizeof...(Args)>::type ih;
ih::doit( forward<Func>(f) , move(args) );
}
Cheers!
SG
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]