Am 13.05.2014 21:52, schrieb Piet:
>
> 20.5.1 of the C++14 draft reads
>
> example:
> template<class F, class Tuple, std::size_t... I>
> decltype(auto) apply_impl(F&& f, Tuple&& t, index_sequence<I...>) {
> return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...);
> }
>
> What I do not understand:
> The I in get<I> is declared as parameter pack in the template
> parameter list, but should be a number or a type of one of the tuple
> elements. Am I wrong?
In this declaration I is a non-type template parameter pack whose
expansion would result in a sequence of N std::size_t values I1, I2,
..IN. And the free std::get overload for tuples (such as std::tuple)
expects a single std::size_t template argument for its first template
parameter. The expansion of
std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...)
would therefore result in the falling call expression:
std::forward<F>(f)(std::get<I1>(std::forward<Tuple>(t)),
std::get<I2>(std::forward<Tuple>(t)),
...,
std::get<IN>(std::forward<Tuple>(t)))
Does this answer your question?
> How f could be declared (see the ellipsis in the call)?
f can be any function object type whose function call operator can be
invoked with the N elements of a given N-tuple.
Lets say the tuple is std::tuple<int, float>, the function object f
could be a type such as
struct MyF
{
void operator()(int, double);
};
or it could be a function pointer such as the followoing one
int (*)(long, float);
just to name some obvious examples.
HTH & Greetings from Bremen,
Daniel Krügler