Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #717

Re: Compile-time integer sequences C++14

Message-ID <lku2ll$pev$1@dont-email.me> (permalink)
Newsgroups comp.std.c++
From Daniel Krügler <daniel.kruegler@googlemail.com>
Subject Re: Compile-time integer sequences C++14
Organization A noiseless patient Spider
References <83ae9935-60ed-4ab2-a52f-c336d4b19b62@googlegroups.com>
Date 2014-05-14 21:19 -0600

Show all headers | View raw


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



--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Find similar


Thread

Compile-time integer sequences C++14 Piet <bremende55@googlemail.com> - 2014-05-13 13:52 -0600
  Re: Compile-time integer sequences C++14 Daniel Krügler <daniel.kruegler@googlemail.com> - 2014-05-14 21:19 -0600

csiph-web