June 2017
Intermediate to advanced
532 pages
12h 59m
English
The helpers we just implemented look horribly complicated. This is because we expand parameter packs with std::initializer_list. Why did we even use that data structure? Let's have a look at for_each again:
auto for_each ([](auto f, auto ...xs) { (void)std::initializer_list<int>{ ((void)f(xs), 0)... };});
The heart of this function is the f(xs) expression. xs is a parameter pack, and we need to unpack it in order to get the individual values out of it and feed them to individual f calls. Unfortunately, we cannot just write f(xs)... using the ... notation, which we already know.
What we can do is constructing a list of values using std::initializer_list, which has a variadic constructor. An expression such as return std::initializer_list<int>{f(xs)...}; ...
Read now
Unlock full access