Re: C++0x: Tuple unpacking as arguments in function call
On Mar 12, 11:46 am, metarox <legault.da...@gmail.com> wrote:
Hello,
I'd like to know what is the way to unpack a tuple into function call
arguments.
Try the following:
template<bool enable, class T> struct enable_if {};
template<class T> struct enable_if<true, T> { typedef T type; };
template<size_t argIndex, size_t argSize, class... Args, class...
Unpacked, class F>
inline typename enable_if<(argIndex == argSize),
void>::type apply_args_impl(const std::tuple<Args...>&& t, F f,
Unpacked&&... u)
{
f(u...); // I think this should be f(std::forward<Unpacked>
(u)...);
}
template<size_t argIndex, size_t argSize, class... Args, class...
Unpacked, class F>
inline typename enable_if<(argIndex < argSize),
void>::type apply_args_impl(const std::tuple<Args...>&& t, F f,
Unpacked&&... u)
{
apply_args_impl<argIndex + 1, argSize>(t, f, u...,
std::get<argIndex>(t));
}
template<class... Args, class F>
inline void apply_args(const std::tuple<Args...>&& t, F f)
{
apply_args_impl<0, sizeof...(Args)>(t, f);
}
There are other possibilities, such as creating a list of indices.
Yechezkel Mett
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]