I've read an answer and stumbled upon sample code below which is Elliott's answer from other SO question HERE
I have issue trying to understand two things (and to know how this syntax is called) :
#include <iostream>
template <typename ... T>
void Foo (T && ... multi_inputs)
{
int i = 0;
([&] (auto & input)
{
// Do things in your "loop" lambda
++i;
std::cout << "input " << i << " = " << input << std::endl;
} (multi_inputs), ...);
}
int main()
{
Foo(2, 3, 4u, (int64_t) 9, 'a', 2.3);
return 0;
}
Two questions each with subquestion:
- At the end of lambda is expression
(multi_inputs), ...
This is equivalent to following simplified syntax:
auto y = [&]() { }();
I don't understand 2 things here, what is the final ()
called, and what it does?
I assume this is some kind of function call operator, but it looks like redundant if taken out of context.
- The entry lambda itself is enclosed into parentheses
()
This is equivalent to following simplified syntax:
(auto y = [&]() { }());
Here I want to understand same, what is this syntax called and what it does in and out of this context? I assume this is also some sort of "parentheses operator" but don't know anything about it.
Knowing what these parentheses do is one thing, but also knowing what is this syntax called is important for understanding ex. to know what to look up on cppreference.